Author: jleroux
Date: Sun Jan 1 09:57:50 2012 New Revision: 1226223 URL: http://svn.apache.org/viewvc?rev=1226223&view=rev Log: A patch from Martin Kreidenweis "Deserialization of arrays with UtilObject.getObject() throws ClassNotFoundException" https://issues.apache.org/jira/browse/OFBIZ-4295 Deserialization of arrays with UtilObject.getObject() throws a ClassNotFoundException. This happened to us when we enabled the distributed cache clear feature and it was sending arrays of EntityExpr objects to other OFBiz instances. The reason is, that the org.ofbiz.base.util.ObjectInputStream calls classLoader.loadClass(name) directly instead of using Class.forName(name, init, classLoader). According to java bug http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6446627 ClassLoader.loadClass() is not intended to being used this way and doesn't support loading arrays. jleroux: Sun/Oracle is pretty clear about that <<[When you want to reflectively load a class by name initiated using a specific class loader, you should not invoke that loader's public loadClass method directly-- instead, you should always use the static three-argument Class.forName method. The ClassLoader.loadClass instance method is more intended for delegation from one class loader to another within a class loading operation (although this is a common confusion and not well described in the documentation). In other words, replace L.loadClass(N) with Class.forName(N,false,L). The Class.forName invocation may eventually end up invoking loadClass on the specified loader, but only after taking care of some other aspects of the VM's standard symbolic class name resolution process-- the significant bit in this case being the support for loading/creation of array classes.]>> More at the link above Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java?rev=1226223&r1=1226222&r2=1226223&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/ObjectType.java Sun Jan 1 09:57:50 2012 @@ -106,7 +106,7 @@ public class ObjectType { if (loader == null) loader = Thread.currentThread().getContextClassLoader(); try { - theClass = loader.loadClass(className); + theClass = Class.forName(className, true, loader); } catch (Exception e) { theClass = classCache.get(className); if (theClass == null) { Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java?rev=1226223&r1=1226222&r2=1226223&view=diff ============================================================================== --- ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java (original) +++ ofbiz/trunk/framework/base/src/org/ofbiz/base/util/UtilIO.java Sun Jan 1 09:57:50 2012 @@ -378,7 +378,7 @@ public final class UtilIO { for (i = offset; i < length && buffer[i] != ':'; i++); if (i > offset && i < length) { String className = new String(buffer, offset, i); - Class<?> type = ClassLoaderContainer.getClassLoader().loadClass(className); + Class<?> type = Class.forName(className, true, ClassLoaderContainer.getClassLoader()); if (buffer[length - 1] == '\n') { length--; } |
Free forum by Nabble | Edit this page |