Yanic Inghelbrecht created JASSIST-151:
------------------------------------------
Summary: javassist.runtime.Desc cannot load array types when using
thread's context classloader
Key: JASSIST-151
URL:
https://issues.jboss.org/browse/JASSIST-151
Project: Javassist
Issue Type: Bug
Affects Versions: 3.15.0-GA
Environment: Any
Reporter: Yanic Inghelbrecht
Assignee: Shigeru Chiba
When the Desc class has to load an array type during instrumentation, it fails when its
global flag useContextClassLoader is set to true.
The following testcase demonstrates this :
---
package test_descForName;
import javassist.runtime.Desc;
import org.junit.Assert;
import org.junit.Test;
public class TestDescForName {
@Test
public void test() {
// try it using classloader of TestDescForName
Desc.useContextClassLoader = false;
Assert.assertTrue(Desc.getClazz("[Ljava.lang.String;") != null);
Thread.currentThread().setContextClassLoader(TestDescForName.class.getClassLoader());
Desc.useContextClassLoader = true;
Assert.assertTrue(Desc.getClazz("[Ljava.lang.String;") != null);
}
}
---
The root cause for this defect is the use of ClassLoader#loadClass in method
getClassObject (which doesn't handle array types):
private static Class getClassObject(String name) throws ClassNotFoundException {
if (useContextClassLoader)
return Thread.currentThread().getContextClassLoader().loadClass(name);
else
return Class.forName(name);
}
The fix is to use the three argument version of Class#forName (which does handle array
types):
private static Class getClassObject(String name) throws ClassNotFoundException {
if (useContextClassLoader)
return Class.forName(name, true, Thread.currentThread().getContextClassLoader());
else
return Class.forName(name);
}
Hooray, my first fix for javassist :)
Best regards,
Yanic
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.jboss.org/secure/ContactAdministrators!default.jspa
For more information on JIRA, see:
http://www.atlassian.com/software/jira