diff --git a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java index 482f407626d..b61b00c91a6 100644 --- a/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java +++ b/org.eclipse.jdt.core.javac/src/org/eclipse/jdt/internal/javac/JavacProblemConverter.java @@ -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;