Skip to content

Commit

Permalink
Avoid NPE with treePath
Browse files Browse the repository at this point in the history
  • Loading branch information
mickaelistria committed Sep 20, 2024
1 parent d635f93 commit 43cca3e
Showing 1 changed file with 3 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1351,15 +1351,11 @@ private int convertNotVisibleAccess(Diagnostic<?> diagnostic) {
if (args[0] instanceof Symbol.MethodSymbol methodSymbol) {
if (methodSymbol.isConstructor()) {
TreePath treePath = getTreePath(jcDiagnostic);
while (!(treePath.getLeaf() instanceof JCMethodDecl) && treePath != null) {
while (treePath != null && !(treePath.getLeaf() instanceof JCMethodDecl)) {
treePath = treePath.getParentPath();
}
if (treePath == null || !(treePath.getLeaf() instanceof JCMethodDecl methodDecl)) {
ILog.get().error("Could not convert diagnostic (" + diagnostic.getCode() + ")\n" + diagnostic + ". Expected the constructor invocation to be in a constructor.");
return 0;
}
boolean isDefault = (methodDecl.sym.flags() & Flags.GENERATEDCONSTR) != 0;
return isDefault ? IProblem.NotVisibleConstructorInDefaultConstructor : IProblem.NotVisibleConstructor;
return treePath != null && treePath.getLeaf() instanceof JCMethodDecl methodDecl && (methodDecl.sym.flags() & Flags.GENERATEDCONSTR) != 0 ?
IProblem.NotVisibleConstructorInDefaultConstructor : IProblem.NotVisibleConstructor;
}

return IProblem.NotVisibleMethod;
Expand Down

0 comments on commit 43cca3e

Please sign in to comment.