Skip to content

Commit

Permalink
Handled the annotation if it is null
Browse files Browse the repository at this point in the history
  • Loading branch information
subyssurendran666 committed Oct 28, 2024
1 parent 4ab9cd9 commit b15d113
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1929,5 +1929,39 @@ public void testBug568629() throws JavaModelException {
assertEquals("Syntax error, insert \"AssignmentOperator Expression\" to complete Expression",cu.getProblems()[6].getMessage());
}

public void testBugGithub2402() throws JavaModelException {
String contents = """
package test;
public class TestClass {
@com.Missing
public TestClass() {
new test.TestClass();
}
}
class com {
}
""";

ASTParser parser = ASTParser.newParser(AST_JLS_LATEST);
parser.setResolveBindings(true);
parser.setStatementsRecovery(true);
parser.setBindingsRecovery(true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
parser.setEnvironment(new String[0], new String[0], null, false);
parser.setSource(contents.toCharArray());
parser.setUnitName("test.TestClass");
ASTNode node = parser.createAST(null);
assertTrue("Should be a compilation unit", node instanceof CompilationUnit);
CompilationUnit cu = (CompilationUnit) node;
TypeDeclaration type = (TypeDeclaration) cu.types().get(0);
MethodDeclaration method = (MethodDeclaration) type.bodyDeclarations().get(0);
ExpressionStatement stmt = (ExpressionStatement) method.getBody().statements().get(0);
ClassInstanceCreation expr = (ClassInstanceCreation) stmt.getExpression();
IMethodBinding ctorBinding = expr.resolveConstructorBinding();
assertNotNull(ctorBinding);
IAnnotationBinding[] annotations = ctorBinding.getAnnotations();
assertNotNull(annotations);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,9 @@ protected IAnnotationBinding[] filterTypeAnnotations(org.eclipse.jdt.internal.co
final boolean isConstructor = this.isConstructor();
for (int i = 0; i < length; i++) {
org.eclipse.jdt.internal.compiler.lookup.AnnotationBinding internalAnnotation = internalAnnotations[i];
if(internalAnnotation == null) {
continue;
}
final ReferenceBinding annotationType = internalAnnotation.getAnnotationType();
long metaTagBits = annotationType.getAnnotationTagBits();

Expand Down Expand Up @@ -612,7 +615,7 @@ protected JavaElement getUnresolvedJavaElement() {
return null;
}
if (!(this.resolver instanceof DefaultBindingResolver)) return null;

DefaultBindingResolver defaultBindingResolver = (DefaultBindingResolver) this.resolver;
if (!defaultBindingResolver.fromJavaProject) return null;
ASTNode domNode = (ASTNode)defaultBindingResolver.bindingsToAstNodes.get(this);
Expand Down

0 comments on commit b15d113

Please sign in to comment.