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 f4c822fa8d03..7a8c7125d277 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 @@ -164,7 +164,7 @@ public class NotNullVerifyingInstrumenter extends ClassVisitor implements Opcode final int syntheticCount = signature == null ? 0 : hasOuterClassParameter ? 1 : Math.max(0, args.length - getSignatureParameterCount(signature)); // workaround for ASM's workaround for javac bug: http://forge.ow2.org/tracker/?func=detail&aid=317788&group_id=23&atid=100023 - final int paramAnnotationOffset = hasOuterClassParameter ? 1 : 0; + final int paramAnnotationOffset = signature == null ? 0 : hasOuterClassParameter ? Math.max(0, args.length - getSignatureParameterCount(signature) - 1) : 0; final Type returnType = Type.getReturnType(desc); final MethodVisitor v = cv.visitMethod(access, name, desc, signature, exceptions); diff --git a/java/java-tests/testData/compiler/notNullVerification/LocalClassImplicitParameters.java b/java/java-tests/testData/compiler/notNullVerification/LocalClassImplicitParameters.java index dca1e568038c..e962aeeac32d 100644 --- a/java/java-tests/testData/compiler/notNullVerification/LocalClassImplicitParameters.java +++ b/java/java-tests/testData/compiler/notNullVerification/LocalClassImplicitParameters.java @@ -1,4 +1,5 @@ import java.lang.annotation.*; +import java.io.*; @Target({ElementType.TYPE_USE, ElementType.PARAMETER}) @interface NotNull {} @@ -19,6 +20,8 @@ public class LocalClassImplicitParameters { public int ok() { foo("a", 2); + create2NotNull("a", "b", null, null, 0, 1, 2, null); + createNullableNotNull(null, "b", null, null, 0, 1, 2, null); return 42; } @@ -26,6 +29,40 @@ public class LocalClassImplicitParameters { foo(null, null); } + + + public void failLocal2NotNull() { + create2NotNull(null, null, null, null, 0, 1, 2, null); + } + + private void create2NotNull(String arg1, String arg2, File vFile, File breakOn, int inclusionLevel, int afterOffset, int beforeOffset, Object changeSet) { + class Test2 implements Serializable { + Test2(@NotNull String test, @NotNull String another) {} + String some() { + return " " + vFile + breakOn + inclusionLevel + changeSet + afterOffset + beforeOffset; + } + } + + new Test2(arg1, arg2).some(); + } + + + + public void failLocalNullableNotNull() { + createNullableNotNull("a", null, null, null, 0, 1, 2, null); + } + + private void createNullableNotNull(String arg1, String arg2, File vFile, File breakOn, int inclusionLevel, int afterOffset, int beforeOffset, Object changeSet) { + class Test3 implements Serializable { + Test3(String test, @NotNull String another) {} + String some() { + return " " + vFile + breakOn + inclusionLevel + changeSet + afterOffset + beforeOffset; + } + } + new Test3(arg1, arg2).some(); + } + + public void failAnonymous() { new _Super("a") { void method(@NotNull java.util.List test){} 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 5fe37fb8e3a3..43e390e6c5a9 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 @@ -212,6 +212,8 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase { Object instance = test.newInstance(); assertEquals(42, test.getMethod("ok").invoke(instance)); verifyCallThrowsException("Argument for @NotNull parameter 'test' of LocalClassImplicitParameters$1Test. must not be null", instance, test.getMethod("failLocal")); + verifyCallThrowsException("Argument for @NotNull parameter 'test' of LocalClassImplicitParameters$1Test2. must not be null", instance, test.getMethod("failLocal2NotNull")); + verifyCallThrowsException("Argument for @NotNull parameter 'another' of LocalClassImplicitParameters$1Test3. must not be null", instance, test.getMethod("failLocalNullableNotNull")); verifyCallThrowsException("Argument for @NotNull parameter 'test' of LocalClassImplicitParameters$1.method must not be null", instance, test.getMethod("failAnonymous")); verifyCallThrowsException("Argument for @NotNull parameter 'param' of LocalClassImplicitParameters$Inner. must not be null", instance, test.getMethod("failInner")); }