4 Replies Latest reply on Aug 17, 2003 8:08 AM by chiba

    try ... catch supported?

    hlship

      I'm having a number of hard to diagnose problems as I try to do more interesting things with Javassist.

      Background: I'm trying to create a proxy object to a stateless session EJB. The proxy implements all the methods of the EJB's remote interface, and performs the JNDI lookup of the home interface and invokes create() on the home interface, caching the result.

      What's happening is I'm getting VerifyErrors when I load the class (that is, when I look up the constructor for the class ... apparently, the verify is deferred until getConstructor() or getMethods()).

      Here's where such a method is created (by my unit tests):

      public MethodFab addMethod(
      int modifiers,
      String name,
      Class returnType,
      Class[] parameterTypes,
      Class[] exceptions,
      String body)
      {
      CtClass ctReturnType = _factory.getClass(_pool, returnType);
      CtClass[] ctParameters = convertClasses(parameterTypes);
      CtClass[] ctExceptions = convertClasses(exceptions);

      CtMethod method = new CtMethod(ctReturnType, name, ctParameters, _ctClass);

      try
      {
      method.setModifiers(modifiers);
      method.setExceptionTypes(ctExceptions);
      method.setBody(body);

      _ctClass.addMethod(method);
      }
      catch (Exception ex)
      {
      throw new ApplicationRuntimeException(
      HiveMind.format(
      "ClassFabImpl.unable-to-add-method",
      name,
      _ctClass.getName(),
      ex.getMessage()),
      ex);
      }

      // Return a MethodFab so the caller can add catches.

      return new MethodFabImpl(_factory, _pool, method);

      }


      And here's the parameters.

      int modifiers= 34
      String name= "_lookupRemote"
      Class returnType= Class (hivemind.test.services.SimpleRemote) (id=49)
      Class[] parameterTypes= null

      exceptions constain Class java.rmi.RemoteException

      Here's the method body:

      {
      if (_remote != null)
      return _remote;

      hivemind.test.services.SimpleHome home = (hivemind.test.services.SimpleHome) getNameLookup().lookup("hivemind.test.services.Simple", _homeClass);

      try
      {
      _remote = home.create();
      }
      catch (javax.ejb.CreateException ex)
      {
      throw new java.rmi.RemoteException(ex.getMessage(), ex);
      }

      return _remote;
      }

      This executes correctly, but when the class is verified:



      java.lang.VerifyError: (class: $EJBProxy_f6fc6f4809_13, method: _lookupRemote signature: ()Lhivemind/test/services/SimpleRemote;) Stack size too large
      at java.lang.Class.getDeclaredConstructors0(Native Method)
      at java.lang.Class.privateGetDeclaredConstructors(Class.java:1590)
      at java.lang.Class.getConstructor0(Class.java:1762)
      at java.lang.Class.getConstructor(Class.java:1002)
      at org.apache.commons.hivemind.service.impl.EJBProxyFactory.invokeConstructor(EJBProxyFactory.java:304)
      at org.apache.commons.hivemind.service.impl.EJBProxyFactory.createCoreServiceImplementation(EJBProxyFactory.java:135)
      at org.apache.commons.hivemind.impl.InvokeFactoryServiceConstructor.constructCoreServiceImplementation(InvokeFactoryServiceConstructor.java:115)
      at org.apache.commons.hivemind.impl.ServiceExtensionPointImpl.constructServiceImplementationInner(ServiceExtensionPointImpl.java:266)
      at org.apache.commons.hivemind.impl.ServiceExtensionPointImpl.constructServiceImplementation(ServiceExtensionPointImpl.java:224)
      at $Proxy_f6fc6f4705_12._service($Proxy_f6fc6f4705_12.java)
      at $Proxy_f6fc6f4705_12.add($Proxy_f6fc6f4705_12.java)
      at hivemind.test.services.TestServices.testEJBProxy(TestServices.java:271)
      at ...

        • 1. Re: try ... catch supported?
          hlship

          I did some minor changes to my project, and added (temporarily) code that writes out the created class files to disk so that I can dissasemble them.

          I've attached the output from dissasembling one of the failed generated classes.

          • 2. Re: try ... catch supported?
            chiba

            Can you tell me your JVM version?

            • 3. Re: try ... catch supported?
              hlship

              C:\workspace\jakarta-tapestry>java -version
              java version "1.4.1_01"
              Java(TM) 2 Runtime Environment, Standard Edition (build 1.4.1_01-b01)
              Java HotSpot(TM) Client VM (build 1.4.1_01-b01, mixed mode)

              Windows XP

              I can provide HiveMind source code as a test case, or this weekend I can try and create a stand-alone test case. Do you use Maven (HiveMind builds using http://maven.apache.org).

              • 4. Re: try ... catch supported?
                chiba

                This problem was a bug. The compiler could not
                compile a try-catch statement correctly. I fixed
                this bug and checked the new source file in.

                Thanks for your bug report.