From 94701d360d3b49518ea5956f03aa899104352625 Mon Sep 17 00:00:00 2001 From: peter Date: Wed, 21 Jun 2017 19:55:55 +0200 Subject: [PATCH] IDEA-146460 Assertions aren't generated for @NotNull method parameters and return types if @NotNull assertion is changed to TYPE_USE only honor only top-level type annotations (IDEA-CR-22158) --- .../notNullVerification/NotNullVerifyingInstrumenter.java | 6 ++++-- .../notNullVerification/TypeUseOnlyAnnotations.java | 7 ++++++- .../NotNullVerifyingInstrumenterTest.java | 1 + 3 files changed, 11 insertions(+), 3 deletions(-) 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 d3535024d9e6..38f2634b6481 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 @@ -177,12 +177,14 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode @Override public AnnotationVisitor visitTypeAnnotation(int typeRef, TypePath typePath, String desc, boolean visible) { + if (typePath != null) return null; + TypeReference ref = new TypeReference(typeRef); if (ref.getSort() == TypeReference.METHOD_RETURN) { - return checkNotNullMethod(desc, mv.visitTypeAnnotation(typeRef, typePath, desc, visible)); + return checkNotNullMethod(desc, mv.visitTypeAnnotation(typeRef, null, desc, visible)); } if (ref.getSort() == TypeReference.METHOD_FORMAL_PARAMETER) { - return checkNotNullParameter(ref.getFormalParameterIndex(), desc, mv.visitTypeAnnotation(typeRef, typePath, desc, visible)); + return checkNotNullParameter(ref.getFormalParameterIndex(), desc, mv.visitTypeAnnotation(typeRef, null, desc, visible)); } return null; } diff --git a/java/java-tests/testData/compiler/notNullVerification/TypeUseOnlyAnnotations.java b/java/java-tests/testData/compiler/notNullVerification/TypeUseOnlyAnnotations.java index 65c3ee6d576b..abf874356189 100644 --- a/java/java-tests/testData/compiler/notNullVerification/TypeUseOnlyAnnotations.java +++ b/java/java-tests/testData/compiler/notNullVerification/TypeUseOnlyAnnotations.java @@ -1,4 +1,5 @@ import java.lang.annotation.*; +import java.util.*; @Target(ElementType.TYPE_USE) @interface FooAnno {} @@ -12,5 +13,9 @@ public class TypeUseOnlyAnnotations { public Object foo2(@FooAnno String arg) { return null; } + + public List<@FooAnno String> foo3(List<@FooAnno String> arg) { + 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 14932c0ee383..bd694d4937e5 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 @@ -187,6 +187,7 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase { Object instance = test.newInstance(); verifyCallThrowsException("@FooAnno method TypeUseOnlyAnnotations.foo1 must not return null", instance, test.getMethod("foo1")); verifyCallThrowsException("Argument 0 for @FooAnno parameter of TypeUseOnlyAnnotations.foo2 must not be null", instance, test.getMethod("foo2", String.class), (String)null); + test.getMethod("foo3", List.class).invoke(instance, (List)null); } public void testTypeUseAndMemberAnnotations() throws Exception {