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

    try ... catch supported?

    Howard Lewis Ship Newbie

      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 ...