[jboss-jira] [JBoss JIRA] (JASSIST-151) javassist.runtime.Desc cannot load array types when using thread's context classloader
Shigeru Chiba (JIRA)
jira-events at lists.jboss.org
Tue Mar 6 11:12:38 EST 2012
[ https://issues.jboss.org/browse/JASSIST-151?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Shigeru Chiba closed JASSIST-151.
---------------------------------
> 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
> Fix For: 3.16.0-GA
>
> Original Estimate: 0 minutes
> Remaining Estimate: 0 minutes
>
> 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
More information about the jboss-jira
mailing list