IDEA-177825 Invalid "Argument 6 for @NotNull parameter must not be null"

This commit is contained in:
peter
2017-08-28 17:48:46 +02:00
parent fb9551fe70
commit 4c2a1be899
3 changed files with 40 additions and 1 deletions
@@ -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);
@@ -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){}
@@ -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.<init> must not be null", instance, test.getMethod("failLocal"));
verifyCallThrowsException("Argument for @NotNull parameter 'test' of LocalClassImplicitParameters$1Test2.<init> must not be null", instance, test.getMethod("failLocal2NotNull"));
verifyCallThrowsException("Argument for @NotNull parameter 'another' of LocalClassImplicitParameters$1Test3.<init> 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.<init> must not be null", instance, test.getMethod("failInner"));
}