2 Replies Latest reply on Jan 19, 2007 6:04 PM by Nicolas Carranza

    ClassNotFoundException for class array type during deseriali

    Terry Newbie


      I am using JBoss 4.0.3SP1 AS with JBoss Remoting 1.4.0 and JDK 1.5.0_06. I have a remote API which returns a class array type. For easier descriptive purposes, let's say the API is

      public Alert[] getAlerts();

      I test this API through a JUnit test case and receive a ClassNotFoundException:

      (socket.SocketClientInvoker 279 ) Got marshalling exception, exiting
      java.lang.ClassNotFoundException: [Lnotification.Alert;
      at java.net.URLClassLoader$1.run(Unknown Source)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
      at java.lang.ClassLoader.loadClass(Unknown Source)
      at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:50)
      at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:120)
      at java.io.ObjectInputStream.readNonProxyDesc(Unknown Source)
      at java.io.ObjectInputStream.readClassDesc(Unknown Source)
      at java.io.ObjectInputStream.readArray(Unknown Source)
      at java.io.ObjectInputStream.readObject0(Unknown Source)
      at java.io.ObjectInputStream.defaultReadFields(Unknown Source)
      at java.io.ObjectInputStream.readSerialData(Unknown Source)
      at java.io.ObjectInputStream.readOrdinaryObject(Unknown Source)
      at java.io.ObjectInputStream.readObject0(Unknown Source)
      at java.io.ObjectInputStream.readObject(Unknown Source)
      at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
      at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)

      To understand this better, I took a look at RemotingClassLoader.java to see the source of the exception (line 50). The ClassCastException is thrown due to a failed second attempt to load the array class using the Java ClassLoader. I didn't quite understand why it was failing since I know my class was visible to my program. I googled for "classnotfoundexception array" and found the following article at:


      which talks about a bug in JDK 1.4.2_06 where deserialization of a class array type results in a ClassNotFoundException. From reading this article, I assumed that a fix for this is in JDK 1.5

      After reading the above article, I modified my unit test program by declaring an empty array of Alert, ie.

      Alert[] testAlerts = new Alert[0];

      right before I invoke my remote API. When I ran my test case with this modification, it went through successfully!

      I ran one more experiment where I removed my array declaration above, changed line 50 in RemotingClassLoader.java to

      loadedClass = Class.forName(name, false, userClassLoader);

      compiled it, and replaced the corresponding class file in jboss-remoting.jar. I then re-ran my test case and it also went through successfully!

      So, this leads to my question: is this a bug in the RemotingClassLoader or is this considered as a bug in java.lang.ClassLoader as reported in my link above?