diff --git a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java
index bbf6cf28bca..83c06cd0d5b 100644
--- a/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java
+++ b/src/main/java/spoon/support/compiler/jdt/JDTTreeBuilder.java
@@ -2558,7 +2558,7 @@ public boolean visit(MarkerAnnotation annotation, BlockScope scope) {
private boolean visitMarkerAnnoation(MarkerAnnotation annotation, BlockScope scope) {
CtAnnotation a = factory.Core().createAnnotation();
- CtTypeReference t = references.getTypeReference(annotation.resolvedType);
+ CtTypeReference t = references.getTypeReference(annotation.resolvedType, annotation.type);
a.setAnnotationType(t);
context.enter(a, annotation);
skipTypeInAnnotation = true;
@@ -2738,7 +2738,7 @@ public boolean visit(MethodDeclaration methodDeclaration, ClassScope scope) {
}
private boolean isContainsInTypeAnnotation(TypeBinding binding, Annotation a) {
- return !binding.hasTypeAnnotations() || !containsInTypeAnnotation(a, binding.getTypeAnnotations());
+ return binding == null || !binding.hasTypeAnnotations() || !containsInTypeAnnotation(a, binding.getTypeAnnotations());
}
private boolean containsInTypeAnnotation(Annotation a, AnnotationBinding[] typeAnnotations) {
diff --git a/src/test/java/spoon/test/reference/TypeReferenceTest.java b/src/test/java/spoon/test/reference/TypeReferenceTest.java
index cd7ee172bd4..2dbfa094cbb 100644
--- a/src/test/java/spoon/test/reference/TypeReferenceTest.java
+++ b/src/test/java/spoon/test/reference/TypeReferenceTest.java
@@ -7,6 +7,7 @@
import spoon.compiler.SpoonResourceHelper;
import spoon.reflect.code.CtFieldRead;
import spoon.reflect.code.CtInvocation;
+import spoon.reflect.code.CtNewClass;
import spoon.reflect.declaration.CtClass;
import spoon.reflect.declaration.CtField;
import spoon.reflect.declaration.CtInterface;
@@ -392,6 +393,25 @@ public void testInvocationWithFieldAccessInNoClasspath() throws Exception {
TestUtils.canBeBuilt("./src/test/resources/noclasspath/TestBot.java", 8, true);
}
+ @Test
+ public void testAnnotationOnMethodWithPrimitiveReturnTypeInNoClasspath() throws Exception {
+ // contract: In no classpath mode, if we have an annotation declared on a method and overridden
+ // from a super class in an anonymous class, we should rewrite correctly the annotation and don't
+ // throw a NPE.
+ final Launcher launcher = new Launcher();
+ launcher.addInputResource("./src/test/resources/noclasspath/A.java");
+ launcher.setSourceOutputDirectory("./target/class-declaration");
+ launcher.getEnvironment().setNoClasspath(true);
+ launcher.run();
+
+ final CtClass