From 7cba7ba21e0bc39d54bfa818a891ddcca2c6cf72 Mon Sep 17 00:00:00 2001 From: peter Date: Thu, 8 Mar 2018 16:15:47 +0100 Subject: [PATCH] IDEA-187753 Duplicate annotation in compiled class when Nullable / NotNull Problems inspection is enabled with custom NonNull annotation --- .../notNullVerification/NotNullVerifyingInstrumenter.java | 2 +- .../notNullVerification/TypeUseAndMemberAnnotations.java | 3 +++ .../NotNullVerifyingInstrumenterTest.java | 6 ++++++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java b/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java index 35bca3d51ffd..d451e97d1fe5 100644 --- a/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java +++ b/java/compiler/instrumentation-util/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java @@ -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); diff --git a/java/java-tests/testData/compiler/notNullVerification/TypeUseAndMemberAnnotations.java b/java/java-tests/testData/compiler/notNullVerification/TypeUseAndMemberAnnotations.java index 2aa1ba5f66cd..961ea95be44d 100644 --- a/java/java-tests/testData/compiler/notNullVerification/TypeUseAndMemberAnnotations.java +++ b/java/java-tests/testData/compiler/notNullVerification/TypeUseAndMemberAnnotations.java @@ -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; } + } \ No newline at end of file diff --git a/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java b/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java index 6e535ed7eef2..234e0694e7f3 100644 --- a/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java +++ b/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java @@ -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 {