[prev in list] [next in list] [prev in thread] [next in thread] 

List:       struts-user
Subject:    Problems with JSONWriter loading classes from Class.forName
From:       Bruno Borges <bruno.borges () gmail ! com>
Date:       2011-07-19 20:51:30
Message-ID: CADKGCnfZN+n-R=CS1C+ysXtp+=Z_h5LjQLZAatK3U8UYEh3+Nw () mail ! gmail ! com
[Download RAW message or body]


I'm not sure about the issue, but I'm now working on a project that has a
fork of the json plugin of Struts 2.1.8.1.

The only difference is this one:

Index: src/main/java/org/apache/struts2/json/JSONWriter.java
===================================================================
--- src/main/java/org/apache/struts2/json/JSONWriter.java (revision 1148509)
+++ src/main/java/org/apache/struts2/json/JSONWriter.java (working copy)
@@ -192,9 +192,14 @@
                 Method baseAccessor = null;
                 if (clazz.getName().indexOf("$$EnhancerByCGLIB$$") > -1) {
                     try {
-                        baseAccessor = Class.forName(
-                                clazz.getName().substring(0,
clazz.getName().indexOf("$$"))).getMethod(
-                                accessor.getName(),
accessor.getParameterTypes());
+ baseAccessor = Thread
+ .currentThread()
+ .getContextClassLoader()
+ .loadClass(
+ clazz.getName().substring(0,
+ clazz.getName().indexOf("$$")))
+ .getMethod(accessor.getName(),
+ accessor.getParameterTypes());
                     } catch (Exception ex) {
                         LOG.debug(ex.getMessage(), ex);
                     }


I think the problem is that projects that use this and are installed on IBM
WebSphere, are having problems. The JAR is deployed as a SharedLib and so,
goes to the parent classloader of the Application. Using Thread's
contextClassLoader seems to fix the problem because that's the one that have
the project's class that will be exported to JSON.

I've tracked this class until trunk and haven't seen any difference about
how it loads CGLib classes.

Shouldn't JSON use the Thread's contextClassLoader, which is a bottom
classloader?

Thanks,
*Bruno Borges*
www.brunoborges.com.br
+55 21 76727099


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic