4 Replies Latest reply on Jun 15, 2006 11:50 PM by ryan dewell

    Unchecked Exception break stateful session bean via EJBNoSuc

    Alexander Hartner Expert

      I have the following services offered by a stateful session bean. When a business exception is thrown by the bean there is no problem, but when there is a unchecked exception (like a Runtime Exception) the bean seems to be removed. I don't see any messages indicating the removal of the bean itself, but any call to the bean after the runtime exception caused a EJBNoSuchObjectException on the client.

      @Stateful
      public class AddressBookBean implements AddressBookRemote, AddressBookLocal
      {
      ..
      public String ping(String ping)
      {
       return ping;
      }
      
      public void createException() throws ContactNotFoundException
      {
       throw new ContactNotFoundException("Testing Exception Handling");
      }
      
      public void createRuntimeException() throws RuntimeException
      {
       throw new RuntimeException("Testing Runtime Exception Handling");
      }
      ..
      }
      


      Here is the client side code:

      System.out.println(addressBook.ping("Message"));
      try
      {
       addressBook.createException();
      }
      catch (ContactNotFoundException cnfe)
      {
      System.err.println("Expected exception received : "+cnfe.getClass().getName());
      //This exception is throws correctly
      }
      
      System.out.println(addressBook.ping("Message"));
      try
      {
       addressBook.createRuntimeException();
      }
      catch (EJBException ee)
      {
       Exception rootException = ee.getCausedByException();
       System.err.println("Root Expected exception received : "+rootException.getClass().getName());
      //The runtime exception is encapsulated in an EJBException
      }
      catch (RuntimeException re)
      {
      System.err.println("Expected exception received : "+re.getClass().getName());
      }
      
      //THIS CALL CAUSES THE javax.ejb.EJBNoSuchObjectException: Could not find Stateful bean:
      System.out.println(addressBook.ping("Message"));
      


      I don't know if this is specified in the EJB3 Spec to behave like this, but it does feel a bit like a bug. Any input on this issue would help me a great deal.