1 Reply Latest reply on Apr 20, 2004 9:37 PM by Matt Clark

    ClassNotFoundException loading an array type using URLClassL

    Matt Clark Newbie

      Hi,

      We've got a strange problem which may be attributed to our environment, but I can't figure out why the environment woul dmake a difference.

      We're calling a method on a stateless session bean that takes in an ArrayList. There are two items in the ArrayList, each an array of one of our objects. In other words:

      ArrayList
      Entry 1: Array of OurClass with 2 OurClass objects
      Entry 2: Array of OurClass with 2 OurClass objects

      When our security proxy calls invoke on the service's security proxy, we see a classnotfoundexception similar to the following in our logs:

      java.lang.ClassNotFoundException: [Lcom.OurClass;
      at java.net.URLClassLoader$1.run(URLClassLoader.java:199)
      at java.security.AccessController.doPrivileged(Native Method)
      at java.net.URLClassLoader.findClass(URLClassLoader.java:187)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
      at org.jboss.invocation.MarshalledValueInputStream.resolveClass(MarshalledValueInputStream.java:85)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.kava:1513)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1435)
      at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1560)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1271)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:324)
      at java.util.ArrayList.readObject(ArrayList.java:547)
      .
      .
      .

      In looking through the code, it looks like it's doing everything correctly up to the point it actually tries to look up OurClass, where it's passing in the string "[Lcom.OurClass" instead of "com.OurClass". I've posted this to JBoss since I'm wondering if MarshalledValueInputStream should be handling this.

      The other variable in this that makes me think it's an environment problem (although as I said I can't rationalize it) is that this occurred when we switched from 1.4.1_02 to 1.4.2_04. Our code (client and server) is being compiled on 1.4.1_02, the client is running on 1.4.1_02, but the server is running with 1.4.2_04. This should cause a problem like this, should it???

      Help!!!

      Thanks in advance,
      Matt

        • 1. Re: ClassNotFoundException loading an array type using URLCl
          Matt Clark Newbie

          In case anyone has this same problem, this ended up being a JVM bug (in my opinion) that was exposed by the way JBoss was loading classes. Basically the ClassLoader.loadClass(String) method doesn't work consistently for loading array types, especially when the array's component type hasn't already been loaded. In other words, if y ou just try this code:

          ClassLoader loader = Thread.currentThread().getContextClassLoader();
          Class clazz = loader.loadClass("[Ljava.lang.Integer;");

          it would give you a ClassNotFoundException. If you added the following line directly above that code:

          Integer[] intArray = new Integer[]{};

          the classloader would be able to load that class.

          The problem in JBoss is that org.jboss.invocation.MarshalledValueInputStream in 3.2.1 only uses the ClassLoader.loadClass(String) method to resolve classes, and doesn't fall back to the Class.forName(String) method, as Sun has now advised.

          This has apparently been fixed in JBoss 3.2.3, although I'm not sure which build.

          Just FYI, this same problem appears in WebStart. The JNLPClassLoader won't be able to load via the array syntax unless you use the above workaround to instantiate that class yourself. How's that for Sun's right hand not knowing what the left is doing ;)

          Thanks,
          Matt