mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-09 20:42:52 +07:00
[^jeka] not-null instrumentation should skip invalid local variable tables in bridge method
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
import java.lang.annotation.*;
|
||||
import java.util.*;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public abstract class MalformedBytecode {
|
||||
|
||||
public static void main() {
|
||||
List<String> list = new ArrayList<>();
|
||||
list.add("aaa");
|
||||
list.add(null);
|
||||
list.add("bbb");
|
||||
new NullTest2().processList(list);
|
||||
}
|
||||
|
||||
public static abstract class NullTest1<T> {
|
||||
protected abstract void processList(T list);
|
||||
}
|
||||
|
||||
public static class NullTest2<T, C extends Collection<@Nullable T>> extends NullTest1<C> {
|
||||
public void processList(C list) {
|
||||
for (@Nullable T s1 : list) {
|
||||
handle(s1);
|
||||
}
|
||||
}
|
||||
|
||||
void handle(@NotNull T arg) {
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target({ ElementType.TYPE_USE })
|
||||
@interface Nullable { }
|
||||
+9
-31
@@ -16,19 +16,14 @@
|
||||
package com.intellij.compiler.notNullVerification;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.compiler.PsiClassWriter;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.compiler.instrumentation.FailSafeClassReader;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
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;
|
||||
import org.jetbrains.org.objectweb.asm.ClassWriter;
|
||||
|
||||
import java.io.File;
|
||||
@@ -44,28 +39,6 @@ import java.util.List;
|
||||
* @author yole
|
||||
*/
|
||||
public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
private boolean myJava6;
|
||||
private IdeaProjectTestFixture myFixture;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
final JavaTestFixtureFactory fixtureFactory = JavaTestFixtureFactory.getFixtureFactory();
|
||||
final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createLightFixtureBuilder();
|
||||
myFixture = testFixtureBuilder.getFixture();
|
||||
myFixture.setUp();
|
||||
myJava6 = SystemInfo.isJavaVersionAtLeast("1.6");
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
try {
|
||||
myFixture.tearDown();
|
||||
}
|
||||
finally {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
public void testSimpleReturn() throws Exception {
|
||||
Class<?> testClass = prepareTest();
|
||||
@@ -189,7 +162,12 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static void verifyCallThrowsException(String expectedError, @Nullable Object instance, Member member, @Nullable Object... args) throws Exception {
|
||||
public void testMalformedBytecode() throws Exception {
|
||||
Class<?> testClass = prepareTest(false);
|
||||
verifyCallThrowsException("Argument 0 for @NotNull parameter of MalformedBytecode$NullTest2.handle must not be null", null, testClass.getMethod("main"));
|
||||
}
|
||||
|
||||
private static void verifyCallThrowsException(String expectedError, @Nullable Object instance, Member member, Object... args) throws Exception {
|
||||
String exceptionText = null;
|
||||
try {
|
||||
if (member instanceof Constructor) {
|
||||
@@ -237,8 +215,8 @@ public class NotNullVerifyingInstrumenterTest extends UsefulTestCase {
|
||||
final String fileName = file.getName();
|
||||
byte[] content = FileUtil.loadFileBytes(file);
|
||||
|
||||
ClassReader reader = new ClassReader(content, 0, content.length);
|
||||
ClassWriter writer = new PsiClassWriter(myFixture.getProject(), myJava6);
|
||||
FailSafeClassReader reader = new FailSafeClassReader(content, 0, content.length);
|
||||
ClassWriter writer = new ClassWriter(ClassWriter.COMPUTE_FRAMES);
|
||||
modified |= NotNullVerifyingInstrumenter.processClassFile(reader, writer);
|
||||
|
||||
byte[] instrumented = writer.toByteArray();
|
||||
|
||||
Reference in New Issue
Block a user