IDEA-187753 Duplicate annotation in compiled class when Nullable / NotNull Problems inspection is enabled with custom NonNull annotation

This commit is contained in:
peter
2018-03-08 16:15:47 +01:00
parent 7bab6026e6
commit 7cba7ba21e
3 changed files with 10 additions and 1 deletions
@@ -188,7 +188,7 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode
@Override
public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) {
AnnotationVisitor av = mv.visitTypeAnnotation(typeRef, null, desc, visible);
AnnotationVisitor av = mv.visitTypeAnnotation(typeRef, typePath, desc, visible);
if (typePath != null) return av;
TypeReference ref = new TypeReference(typeRef);
@@ -1,6 +1,7 @@
import java.lang.annotation.*;
@Target({ElementType.TYPE_USE, ElementType.METHOD, ElementType.PARAMETER})
@Retention(RetentionPolicy.RUNTIME)
@interface FooAnno {}
public class TypeUseAndMemberAnnotations {
@@ -13,4 +14,6 @@ public class TypeUseAndMemberAnnotations {
return null;
}
public @FooAnno java.util.List<@FooAnno String> returnType() { return null; }
}
@@ -200,6 +200,12 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
Object instance = test.newInstance();
verifyCallThrowsException("@FooAnno method TypeUseAndMemberAnnotations.foo1 must not return null", instance, test.getMethod("foo1"));
verifyCallThrowsException("Argument 0 for @FooAnno parameter of TypeUseAndMemberAnnotations.foo2 must not be null", instance, test.getMethod("foo2", String.class), (String)null);
Method returnType = test.getMethod("returnType");
verifyCallThrowsException("@FooAnno method TypeUseAndMemberAnnotations.returnType must not return null", instance, returnType);
assertSize(1, returnType.getAnnotations());
assertSize(1, returnType.getAnnotatedReturnType().getAnnotations());
}
public void testMalformedBytecode() throws Exception {