7 Replies Latest reply on Sep 6, 2006 4:55 PM by David Green

    UndeclaredThrowableException in RC5

    Alexander Hartner Expert

      I have a ApplicationException which when thrown from a session bean results in an UndeclaredThrowableException on the remote client side.

      I have contructed the following service to illustrate my problem :

      public void createException() throws ContactNotFoundException
      {
       throw new ContactNotFoundException();
      }
      


      The exception itself is a standard Java Exception. I tried adding the ApplicationException annotation, but it did not change the result.

      public class ContactNotFoundException extends Exception implements Serializable
      {
       public ContactNotFoundException()
       {
       }
      }
      


      When the method is invoked the client reports the following :


      java.lang.reflect.UndeclaredThrowableException
      at $Proxy36.createException(Unknown Source)
      at com.ejb3workshop.entity.testCases.ExceptionTestCase.runTest(Unknown Source)
      at com.ejb3workshop.entity.testCases.ExceptionTestCase.main(Unknown Source)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:585)
      at org.apache.tools.ant.taskdefs.ExecuteJava.run(ExecuteJava.java:193)
      at org.apache.tools.ant.taskdefs.ExecuteJava.execute(ExecuteJava.java:130)
      at org.apache.tools.ant.taskdefs.Java.run(Java.java:705)
      at org.apache.tools.ant.taskdefs.Java.executeJava(Java.java:178)
      at org.apache.tools.ant.taskdefs.Java.execute(Java.java:84)
      at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:275)
      at org.apache.tools.ant.Task.perform(Task.java:364)
      at org.apache.tools.ant.Target.execute(Target.java:341)
      at org.apache.tools.ant.Target.performTasks(Target.java:369)
      at org.apache.tools.ant.Project.executeTarget(Project.java:1214)
      at org.apache.tools.ant.Project.executeTargets(Project.java:1062)
      at org.apache.tools.ant.module.bridge.impl.BridgeImpl.run(BridgeImpl.java:234)
      at org.apache.tools.ant.module.run.TargetExecutor.run(TargetExecutor.java:242)
      at org.netbeans.core.execution.RunClassThread.run(RunClassThread.java:125)
      Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;
      at org.apache.tools.ant.AntClassLoader.findClassInComponents(AntClassLoader.java:1149)
      at org.apache.tools.ant.AntClassLoader.findClass(AntClassLoader.java:1090)
      at org.apache.tools.ant.AntClassLoader.loadClass(AntClassLoader.java:966)
      at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
      at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:50)
      at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:120)
      at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1538)
      at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1460)
      at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1585)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1293)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1912)
      at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1836)
      at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1713)
      at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1299)
      at java.io.ObjectInputStream.readObject(ObjectInputStream.java:339)
      at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128)
      at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66)
      at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:260)
      at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:131)
      at org.jboss.remoting.Client.invoke(Client.java:258)
      at org.jboss.remoting.Client.invoke(Client.java:221)
      at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65)
      at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:98)
      at org.jboss.ejb3.stateful.StatefulRemoteProxy.invoke(StatefulRemoteProxy.java:133)
      ... 21 more


      I tried looking in the examples as well as the specification, but did not find anything related. I tested a similar example on RC3 and it worked correctly.

      Thanks

        • 1. Re: UndeclaredThrowableException in RC5
          Bill Burke Master

          what does your business interface look like? The business interface must throw the same exception (unless it is a RuntimeException of course!)

          • 2. Re: UndeclaredThrowableException in RC5
            Alexander Hartner Expert

            Hi Bill,

            Thanks for the quick feedback. The business interface contains the following:

            package com.ejb3workshop.entity;
            import javax.ejb.Remote;
            
            @Remote
            public interface AddressBookRemote extends AddressBookServices
            {
            }
            


            and the "services" interface has :

            package com.ejb3workshop.entity;
            
            import java.io.Serializable;
            import java.util.Collection;
            public interface AddressBookServices extends Serializable
            {
             ...
             public void createException() throws ContactNotFoundException;
            }
            


            • 3. Re: UndeclaredThrowableException in RC5
              Bill Burke Master

              Did you see this in the stack trace? The actual exception being thrown is ClassNotFoundException, not ContactNotFoundException:

              Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement;

              Maybe your client doesn't have ContactNotFoundException in its classpath?

              • 4. Re: UndeclaredThrowableException in RC5
                Alexander Hartner Expert

                Hi Bill,

                I added the following lines to the client

                Exception e = new ContactNotFoundException();
                System.out.println(e.getClass().getName());
                

                just to make sure the client has the classes in the classpath. The class name is printed without any errors. I get the UndeclaredThrowableException every time an exception occurs on the backend. Even exceptions when the container can't find an entity using a finder method.

                I use the following ANT script to build up my classpath :


                <?xml version="1.0"?>

                <project name="EntityBean" default="info" basedir=".">

                <property environment="env"/>
                <property file="build.properties"/>
                <property name="src.dir" value="src"/>
                <property name="build.dir" value="build"/>
                <property name="jarfile" value="${ant.project.name}.ejb3"/>
                <property name="jbossServer.dir" value="${env.JBOSS_HOME}/server/default"/>
                <property name="deployall.dir" value="${jbossServer.dir}/deploy"/>

                <!-- Set up java.class.path -->
                <path id="build.path">
                <fileset dir="${env.JBOSS_HOME}/lib">
                <include name="**/*.jar"/>
                </fileset>
                <fileset dir="${jbossServer.dir}/lib">
                <include name="**/*.jar"/>
                </fileset>
                <fileset dir="${jbossServer.dir}/deploy/ejb3.deployer">
                <include name="*.jar"/>
                </fileset>
                <fileset dir="${jbossServer.dir}/deploy/jboss-aop-jdk50.deployer">
                <include name="*.jar"/>
                </fileset>
                <pathelement path="${build.dir}"/>
                <pathelement path="."/>
                </path>

                <target name="init">
                <echo message="JBOSS : ${env.JBOSS_HOME}"/>
                </target>

                <target name="clean">
                <delete dir="${build.dir}"/>
                <mkdir dir="${build.dir}"/>
                </target>

                <target name="compile" depends="init">
                <javac srcdir="${src.dir}" destdir="${build.dir}">
                <compilerarg value="-Xlint:unchecked"/>
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </javac>
                </target>

                <target name="jar" depends="compile">
                <jar jarfile="${jarfile}" basedir="${build.dir}">
                <metainf file="persistence.xml"/>
                </jar>
                </target>

                <target name="deploy" depends="jar">
                <copy file="${jarfile}" todir="${deployall.dir}" />
                </target>

                <target name="undeploy">
                <delete file="${deployall.dir}/${jarfile}" />
                </target>

                <target name="client" depends="compile">
                <java classname="com.ejb3workshop.entity.Client" fork="yes">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="testCase1" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.TestCase1" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="testCase2" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.TestCase2" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="testCase3" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.TestCase3" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="testCase4" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.TestCase4" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="testCase5" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.TestCase5" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="exceptionTestCase" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.ExceptionTestCase" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                <target name="findTestCase" depends="compile">
                <java classname="com.ejb3workshop.entity.testCases.FindTestCase" fork="no">
                <classpath>
                <path refid="build.path"/>
                </classpath>
                </java>
                </target>

                </project>


                • 5. Re: UndeclaredThrowableException in RC5
                  Alexander Hartner Expert

                  I solved the problem by forking (add fork="yes") in my ant script for the client task. Must have been Netbeans getting confused with the classpath.

                  Sorry to cause all this confusion. Now I really feel stupid :-(

                  • 6. Re: UndeclaredThrowableException in RC5
                    Bill Burke Master

                    YOu answer a lot of forum posts, so you are forgiven...

                    • 7. Re: UndeclaredThrowableException in RC5
                      David Green Newbie

                      I'm also having a similar problem, however fork="yes" in my Ant script doesn't fix the problem. Here's my stack trace:

                      java.lang.reflect.UndeclaredThrowableException at $Proxy0.postNotification(Unknown Source) at com.hgea.hch.service.HchClientDelegate.postNotification(HchClientDelegate.java:99) at com.hgea.hch.client.RemoteHchClientTest.testRemotePostNotification(RemoteHchClientTest.java:38)Caused by: java.lang.ClassNotFoundException: [Ljava.lang.StackTraceElement; at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:306) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276) at java.lang.ClassLoader.loadClass(ClassLoader.java:251) at org.jboss.remoting.loading.RemotingClassLoader.loadClass(RemotingClassLoader.java:50) at org.jboss.remoting.loading.ObjectInputStreamWithClassLoader.resolveClass(ObjectInputStreamWithClassLoader.java:139) at java.io.ObjectInputStream.readNonProxyDesc(ObjectInputStream.java:1575) at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1496) at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1624) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1323) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.defaultReadFields(ObjectInputStream.java:1945) at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1869) at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1753) at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1329) at java.io.ObjectInputStream.readObject(ObjectInputStream.java:351) at org.jboss.remoting.serialization.impl.java.JavaSerializationManager.receiveObject(JavaSerializationManager.java:128) at org.jboss.remoting.marshal.serializable.SerializableUnMarshaller.read(SerializableUnMarshaller.java:66) at org.jboss.remoting.transport.socket.SocketClientInvoker.transport(SocketClientInvoker.java:279) at org.jboss.remoting.RemoteClientInvoker.invoke(RemoteClientInvoker.java:143) at org.jboss.remoting.Client.invoke(Client.java:525) at org.jboss.remoting.Client.invoke(Client.java:488) at org.jboss.aspects.remoting.InvokeRemoteInterceptor.invoke(InvokeRemoteInterceptor.java:55) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.tx.ClientTxPropagationInterceptor.invoke(ClientTxPropagationInterceptor.java:61) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.aspects.security.SecurityClientInterceptor.invoke(SecurityClientInterceptor.java:55) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.remoting.IsLocalInterceptor.invoke(IsLocalInterceptor.java:65) at org.jboss.aop.joinpoint.MethodInvocation.invokeNext(MethodInvocation.java:101) at org.jboss.ejb3.stateless.StatelessRemoteProxy.invoke(StatelessRemoteProxy.java:102) ... 18 more