2 Replies Latest reply on Apr 29, 2002 8:48 PM by Mike Squance

    Error after throwing RuntimeException from stateful session

    Mike Squance Newbie


      I have searched the forums and cannot find an answer for the issue regarding getting a FileNotFoundException when attempting to access a stateful session bean after an EJBException or other RuntimeException is thrown from the previous method call to the session bean.

      The specific error is:
      Could not activate; nested exception is: java.io.FileNotFoundException: C:\profiler\jboss\db\sessions\TestSession\1019776561611.ser (The system cannot find the file specified)

      I am using JBoss 2.4.1.

      It seems that the container is trying to activate the bean, even though it hasn't passivated it (My logging indicates that ejbPassivate has not been called).

      It is very easy to reproduce. I created a session bean that has 2 methods, one that does nothing and one that throws an EJBException. The bean has not data members. I have a client that creates an instance of the bean, calls the method that throws the exception, then calls either of the other methods and it will fail.

      Has anyone been able to confirm if this is a bug? If it's not a bug, any suggestions on what I am doing wrong?


        • 1. Re: Error after throwing RuntimeException from stateful sess
          Annegret Sternagel Newbie

          Hi Mike,
          this behavior is according to the EJB Spec, read the chapter ExceptionHandling.
          jboss discards the SessionBean after a RuntimeException or java.rmi.RemoteException.

          To avoid this You can define an ApplicationException that MUST NOT extend from java.rmi.RemoteException but from java.lang.Exception, catch all Exceptions in your bean method and throw the ApplicationException instead.


          • 2. Re: Error after throwing RuntimeException from stateful sess
            Mike Squance Newbie


            I did see the reference to the "Discard instance" on one of the other posts on this subject, but I wasn't convinced that it was the answer. The EJB spec footnote says: "Discard instance means that the Container must not invoke any business methods or container callbacks
            on the instance."

            To me that does not imply that the bean is no longer usable. Also, the same information about discarding the instance is stated for entity beans, but entity beans are still accessible after a run-time exception.

            My thought was also that if this is design intent, the exception being thrown would not be the FileNotFoundException, but something more meaningful.