1 Reply Latest reply on Mar 21, 2003 4:49 AM by paulg

    NonSerializableFactory ClassCastException

    paulg

      Can anyone help with the following - thanks.

      I'm trying to share an object between a custom JBoss MBean and an Axis service running in the same JBOSS JVM.

      When I look up the object ( JNDI) in the axis service, and call object.getClass(). I get the same name as the class that I am trying to cast to. If I look at both classes in a debugger, they look identical.

      BUT, when I cast the object, I get a class cast exception. Any ideas - I am completely stumped!

      e.g.

      // **** JNDI binding ****

      // Some class that does not implement Serializable
      Object nonserializable = new com.NonSerializable("Test class");

      // An arbitrary key to use in the StringRefAddr. The best key is the jndi
      // name that the object will be bound under.
      String key = "abc";

      // This places nonserializable into the NonSerializableFactory hashmap under key
      NonSerializableFactory.rebind(key, nonserializable);

      Context ctx = new InitialContext();
      // Bind a reference to nonserializable using NonSerializableFactory as the ObjectFactory
      String className = nonserializable.getClass().getName();
      String factory = NonSerializableFactory.class.getName();
      StringRefAddr addr = new StringRefAddr("nns", key);
      Reference memoryRef = new Reference(className, addr, factory, null);
      ctx.rebind(key, memoryRef);




      // **** Axis Service lookup ****
      Object obj = _context.lookup("abc");
      System.out.println(obj.getClass().getName());
      // Outputs "com.NonSerializable"
      System.out.println("Casting " + (com.NonSerializable) obj);
      // throws ClassCastException

        • 1. Re: NonSerializableFactory ClassCastException
          paulg

          This was a classloader issue:

          I had the same class being loaded by 2 different classloaders - the web service's class loader and the MBeans classloader. The actual class was installed locally for both services. By extracting the appropriate class ( i.e. in this case 'com.NonSerializable') or interface into the JBoss lib directory ( i.e. $JBOSS_HOME/server/xxx/lib) this problem can be resolved.