From e43cdebd16ea8244676636dd92ec21d6bf3aa6f5 Mon Sep 17 00:00:00 2001 From: nik Date: Thu, 5 Aug 2010 09:08:01 +0400 Subject: [PATCH] correctly fixed not-null instrumentation for enums (IDEA-56943) --- .../NotNullVerifyingInstrumenter.java | 6 ++--- .../EnumConstructorSecondParam.java | 23 +++++++++++++++++++ .../NotNullVerifyingInstrumenterTest.java | 6 +++++ 3 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 java/java-tests/testData/compiler/notNullVerification/EnumConstructorSecondParam.java diff --git a/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java b/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java index 7990ab4d73f1..62cf1608aa7d 100644 --- a/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java +++ b/java/compiler/notNull/src/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenter.java @@ -122,8 +122,8 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode } for (int p = 0; p < myNotNullParams.size(); ++p) { int var = ((access & ACC_STATIC) == 0) ? 1 : 0; - int param = ((Integer)myNotNullParams.get(p)).intValue() - mySyntheticCount; - for (int i = 0; i < param + startParameter; ++i) { + int param = ((Integer)myNotNullParams.get(p)).intValue(); + for (int i = 0; i < startParameter + param; ++i) { var += args[i].getSize(); } mv.visitVarInsn(ALOAD, var); @@ -132,7 +132,7 @@ public class NotNullVerifyingInstrumenter extends ClassAdapter implements Opcode mv.visitJumpInsn(IFNONNULL, end); generateThrow(IAE_CLASS_NAME, - "Argument " + param + " for @NotNull parameter of " + myClassName + "." + name + " must not be null", end); + "Argument " + (param - mySyntheticCount) + " for @NotNull parameter of " + myClassName + "." + name + " must not be null", end); } } diff --git a/java/java-tests/testData/compiler/notNullVerification/EnumConstructorSecondParam.java b/java/java-tests/testData/compiler/notNullVerification/EnumConstructorSecondParam.java new file mode 100644 index 000000000000..2081b5fa7142 --- /dev/null +++ b/java/java-tests/testData/compiler/notNullVerification/EnumConstructorSecondParam.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2010 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +import org.jetbrains.annotations.NotNull; + +public enum EnumConstructorSecondParam { + Value("1", "2"); + + EnumConstructorSecondParam(String s1, @NotNull String s2) { + } +} diff --git a/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java b/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java index 12f5e0aa4f84..e8d6dd9d56cf 100644 --- a/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java +++ b/java/java-tests/testSrc/com/intellij/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java @@ -63,6 +63,12 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase { assertNotNull(field); } + public void testEnumConstructorSecondParam() throws Exception { + Class testClass = prepareTest(); + Object field = testClass.getField("Value"); + assertNotNull(field); + } + private static void verifyCallThrowsException(final String expectedError, final Object instance, final Method method, final Object... args) throws IllegalAccessException { String exceptionText = null; try {