struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Bruno Borges <bruno.bor...@gmail.com>
Subject Problems with JSONWriter loading classes from Class.forName
Date Tue, 19 Jul 2011 20:51:30 GMT
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

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message