don't instrument bridge methods for @NotNull (IDEA-146977)

This commit is contained in:
peter
2015-10-28 17:03:44 +01:00
parent bc3d345647
commit 29b95875b9
3 changed files with 43 additions and 1 deletions
@@ -0,0 +1,22 @@
import org.jetbrains.annotations.NotNull;
public class SkipBridgeMethods {
public static void main() {
A a = new B();
a.getObject(null);
}
}
class A {
@NotNull
public Object getObject(Object arg) {
return new Object();
}
}
class B extends A {
@NotNull
public String getObject(@NotNull Object arg) {
return arg.toString();
}
}
@@ -19,12 +19,13 @@ import com.intellij.JavaTestUtil;
import com.intellij.compiler.PsiClassWriter;
import com.intellij.openapi.util.SystemInfo;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.testFramework.IdeaTestCase;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.testFramework.UsefulTestCase;
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
import com.intellij.util.ArrayUtil;
import com.intellij.util.ExceptionUtil;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.org.objectweb.asm.ClassReader;
@@ -172,6 +173,21 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
assertNotNull(aClass.newInstance());
}
public void testSkipBridgeMethods() throws Exception {
final Class<?> testClass = prepareTest();
try {
testClass.getMethod("main").invoke(null);
fail();
}
catch (InvocationTargetException e) {
//noinspection ThrowableResultOfMethodCallIgnored
assertInstanceOf(e.getCause(), IllegalArgumentException.class);
String trace = ExceptionUtil.getThrowableText(e.getCause());
assertEquals("Exception should happen in real, non-bridge method: " + trace,
2, StringUtil.getOccurrenceCount(trace, "B.getObject(SkipBridgeMethods"));
}
}
private static void verifyCallThrowsException(String expectedError, @Nullable Object instance, Member member, @Nullable Object... args) throws Exception {
String exceptionText = null;
try {