[jboss-jira] [JBoss JIRA] Created: (JASSIST-74) modifying a method containing a switch statement using IBM JVM throws ArrayIndexOutOfBoundsException
Mooky Grand (JIRA)
jira-events at lists.jboss.org
Mon Mar 9 12:00:54 EDT 2009
modifying a method containing a switch statement using IBM JVM throws ArrayIndexOutOfBoundsException
----------------------------------------------------------------------------------------------------
Key: JASSIST-74
URL: https://jira.jboss.org/jira/browse/JASSIST-74
Project: Javassist
Issue Type: Bug
Affects Versions: 3.8.1.GA
Environment: OS: Probably all. I produced it on Windows
JVM: does not happen with Sun JVM (at least the versions I used). Does happen with IBM's JVM. I used the following version:
java version "1.5.0"
Java(TM) 2 Runtime Environment, Standard Edition (build pwi32dev-20060511 (SR2))
IBM J9 VM (build 2.3, J2RE 1.5.0 IBM J9 2.3 Windows XP x86-32 j9vmwi3223-20060504 (JIT enabled)
J9VM - 20060501_06428_lHdSMR
JIT - 20060428_1800_r8
GC - 20060501_AA)
JCL - 20060511a
This version comes bundled with Websphere 6.1 ND. The Exact version that I used is "WebSphere Platform 6.1 [ND 6.1.0.0 b0620.14]"
Reporter: Mooky Grand
Assignee: Shigeru Chiba
First the exception that I see:
Exception in thread "main" java.lang.ArrayIndexOutOfBoundsException: -2147483648
at javassist.bytecode.CodeIterator.insertGap2(CodeIterator.java(Compiled Code))
at javassist.bytecode.CodeIterator.insertGap0(CodeIterator.java:656)
at javassist.bytecode.CodeIterator.insertGap(CodeIterator.java:640)
at javassist.bytecode.CodeIterator.insertGapCore(CodeIterator.java:467)
at javassist.bytecode.CodeIterator.insert0(CodeIterator.java:370)
at javassist.bytecode.CodeIterator.insertEx(CodeIterator.java:339)
at javassist.CtBehavior.insertBefore(CtBehavior.java:671)
at javassist.CtBehavior.insertBefore(CtBehavior.java:640)
at sample.MyTest2.main(MyTest2.java:26)
>From the little analysis I did I discovered the following:
1. The problem is not reproduced using Sun's JVM.
2. The method being modified must be of a certain length
3. The method must have a switch statement.
4. The added code should be containe dinside a try-catch block.
All of these are demonstrated in my example.
MyTest2.java:
package sample;
import javassist.*;
import javassist.expr.*;
public class MyTest2 {
public static void main(String[] args) throws Exception {
ClassPool pool = ClassPool.getDefault();
final CtClass jdbcCt = pool.get("sample.Bla");
final CtMethod fooMethod = jdbcCt.getDeclaredMethod("foo");
String sourceCode = "{"
+ "System.out.println(\"Bla!\");"
+ "}";
String toInsert =
" try " +
" { " +
sourceCode +
" } " +
" catch(Throwable e) " +
" { " +
" e.printStackTrace(); " +
" } ";
fooMethod.insertBefore(toInsert);
jdbcCt.writeFile(); // update the class file
}
}
Bla.java:
package sample;
public class Bla
{
protected void foo()
{
int j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
j = 4;
switch (1)
{
default:
}
}
}
When I remove some of the repeating statements the exception goes away (BTW, if I remove just one there's no exception but the resulting file is corrupted).
Essentially, this prevents me from using Javassist under IBM's JVM for large methods that contain switch statements.
I've reproduced this problem using javassist 3.4, 3.8 & 3.9.
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: https://jira.jboss.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira
More information about the jboss-jira
mailing list