The following issue impacts the copy of BCEL included with our copy of jaxp. This bug report is to include the fix for this issue into the JDK.
[ Bug 39695 - java.lang.ClassFormatError: LVTT entry for 'local' in class file org/shiftone/jrat/test/dummy/CrashTestDummy does not match any LVT entry ]
https://issues.apache.org/bugzilla/show_bug.cgi?id=39695
Simple test case:
=== TestCase.java
import com.sun.org.apache.bcel.internal.classfile.ClassParser;
import com.sun.org.apache.bcel.internal.classfile.ConstantClass;
import com.sun.org.apache.bcel.internal.classfile.ConstantPool;
import com.sun.org.apache.bcel.internal.classfile.ConstantUtf8;
import com.sun.org.apache.bcel.internal.classfile.JavaClass;
import com.sun.org.apache.bcel.internal.classfile.Method;
import com.sun.org.apache.bcel.internal.generic.ClassGen;
import com.sun.org.apache.bcel.internal.generic.MethodGen;
import java.util.ArrayList;
import java.io.FileOutputStream;
class TestCase {
public static void main(String[] args) throws Exception {
transform();
}
private static void transform() throws Exception {
JavaClass jc = new ClassParser("TestCase.class").parse();
//rename class
ConstantPool cp = jc.getConstantPool();
int cpIndex = ((ConstantClass)cp.getConstant(jc.getClassNameIndex())).getNameIndex();
cp.setConstant(cpIndex, new ConstantUtf8("NewTestCase"));
ClassGen gen = new ClassGen(jc);
Method[] methods = jc.getMethods();
int index;
for (index = 0; index < methods.length; index++) {
if (methods[index].getName().equals("doSomething")) {
break;
}
}
Method m = methods[index];
MethodGen mg = new MethodGen(m, gen.getClassName(), gen.getConstantPool());
gen.replaceMethod(m, mg.getMethod());
gen.getJavaClass().dump(new FileOutputStream("NewTestCase.class"));
Class.forName("NewTestCase");
}
public void doSomething(double d, ArrayList<Integer> list) {
}
}
===
Example run:
===
$ javac -g TestCase.java
< ... warning about using an internal API removed >
$ java TestCase
Exception in thread "main" java.lang.ClassFormatError: LVTT entry for 'list' in class file NewTestCase does not match any LVT entry
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(ClassLoader.java:631)
at java.lang.ClassLoader.defineClass(ClassLoader.java:615)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:141)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:283)
at java.net.URLClassLoader.access$000(URLClassLoader.java:58)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at TestCase.transform(TestCase.java:36)
at TestCase.main(TestCase.java:15)
===