Announcement Announcement Module
Collapse
No announcement yet.
Strange Behavior of BeanCreationExceptio Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Strange Behavior of BeanCreationExceptio

    Hi Folks,

    I am encountering a very strange problem (well I don't know it is a problem or a conceptual issue at this point). I am having a Spring Managed SLSB deployed on one of our servers. The ApplicationContext.xml file (specified in "ejb/BeanFactoryPath" enviro var is missing some classpath resource)

    I have got one local client to test it. The SLSB is having some configuration error in its ApplicationContext.xml, so it throws a Remote Exception, with BeanCreationException as initCause to it, everytime a call is made to it (which is very well expected).

    The point to ponder here is that if I have the same Spring JAR in my classpath then it says:

    java.io.InvalidClassException: org.springframework.beans.BeansException; local class incompatible: stream classdesc serialVersionUID = 5951866628951717299, local class serialVersionUID = -2725566157126749441


    If i remove the Spring JAR from the classpath and try to introspect on the initCause of the RemoteException (which is BeanCreationException), surprisingly I am able to see all the public methods declared in the class!

    Then if I try to invoke one (say getResourceDescription) method on the BeanCreationException instance, it actually allows me to that (printing "class path resource [ApplicationContext.xml]" on the console). What I am wondering is that how can unmarshalling happen on a Object whose class we are not having in the classpath (and we are having an object of that class on the heap)?

    Lastly, I put my Java notions aside to write a custom class, MyException extending RuntimeException and serialized it to a file "C://exception.ser". Now i try to deserialize this object on a separate project which is not having MyException in the classpath, I get a java.lang.ClassNotFoundException straightaway at the very place I try to do a objectInputStream.readObject().


    Could anybody put a insight on this? Source of all the stated files are below:


    MyException Class doing serialization as well

    Code:
    package com.test;
    
    import java.io.FileOutputStream;
    import java.io.ObjectOutputStream;
    import java.rmi.RemoteException;
    
    @SuppressWarnings("serial")
    public class MyException extends RuntimeException {
    
    	public MyException() {
    	}
    
    	public MyException(String message) {
    		super(message);
    	}
    
    	public MyException(Throwable cause) {
    		super(cause);
    	}
    
    	public MyException(String message, Throwable cause) {
    		super(message, cause);
    	}
    	
    	public String getAmazingMessage() {
    		return "Whoa!";
    	}
    	
    	public static void main(String[] args) throws Exception {
    		System.out.println("Serializing an instance of MyException");
    		String path = "C://exception.ser";
    		MyException exception = new MyException("This is gonna deserialize!");
    		ObjectOutputStream objectOutputStream = new ObjectOutputStream(new FileOutputStream(path));
    		objectOutputStream.writeObject(new RemoteException("RemoteException", exception));
    //		objectOutputStream.writeObject(exception); // This cause the same output
    		objectOutputStream.flush();
    		objectOutputStream.close();
    		System.out.println("An instance of MyException serialized at " + path);
    
    //		This thing completes normally 
    	}
    
    }

    Deserialization of MyExceptionClass

    Code:
    package com.test;
    
    import java.io.FileInputStream;
    import java.io.ObjectInputStream;
    import java.lang.reflect.Method;
    
    
    public class TestDeser {
    		public static void main(String[] args) throws Exception {
    			String path = "C://exception.ser";
    			ObjectInputStream objectInputStream = new ObjectInputStream(new FileInputStream(path));
    			Object object = objectInputStream.readObject(); // Exception comes right here
    			Class clazz = object.getClass();
    			System.out.println("Class of Object: " + clazz);
    			System.out.println("Name of Object: " + clazz.getName());
    	//		Class.forName(clazz.getName());
    			Method[] methods = clazz.getMethods();
    			for (Method method : methods) {
    				System.out.println(method.getName());
    				if(method.getName().equals("getAmazingMessage")) {
    					Object returnValue = method.invoke(object, (Object[])null);
    					System.out.println("Invoking getAmazingMessage() on bean returned: " + returnValue);
    				}
    			}
    		}
    }


    Service Client
    Code:
    package com.test;
    
    import java.lang.reflect.Method;
    public class ServiceClient {
    
    
    	public static void main(String[] args) throws Exception{
    		System.out.println("Calling DID Manager under try-catch ...");
    		
    		try {
    			ServicerLocator service = new ServicerLocator();
    			service.getAccountInfo(3584);
    		} catch (Exception e) {
    			Throwable cause = e.getCause();
    			Class<? extends Throwable> bceClass = cause.getClass();
    			System.out.println("Class of the Nested Exception: " + bceClass);
    			System.out.println("Name of the Nested Exception Class: " + bceClass.getName());
    //			Class.forName(bceClass.getName());
    			Method[] methods = bceClass.getMethods();
    			for (Method method : methods) {
    				System.out.println(method.getName());
    				if(method.getName().equals("getResourceDescription")) {
    					Object returnValue = method.invoke(cause, (Object[])null);
    					System.out.println("Invoking getResourceDescription() on bean returned: " + returnValue);
    				}
    			}
    		}
    	}
    
    }
    Last edited by vidhuz; Nov 3rd, 2009, 11:14 AM.

  • #2
    Could any spring community member answer this question please?

    Comment


    • #3
      A solution with Spring´s versions

      My friend, it is very likely that you already solve your problem, I am posting that for help some one else.

      Today thats happends to me and the mistake were in the versions of Spring that I was using, I had spring-core 2.5.6 and the others Spring´s librarys were 2.5.3

      Comment

      Working...
      X