1 2 Previous Next 15 Replies Latest reply: Mar 30, 2010 1:28 PM by Kabir Khan RSS

Issues using Javassist TypeInfoFactory in other projects

Kabir Khan Master

Starting this thread to keep track of what is going wrong when using the Javassist version of TypeInfo

 

The first issue is that javassist itself did not understand things like

 

@SomeAnnotation(clazz=org.blah.Something[])

 

https://jira.jboss.org/jira/browse/JASSIST-111

  • 1. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    Kabir Khan wrote:

     

    Starting this thread to keep track of what is going wrong when using the Javassist version of TypeInfo

     

    The first issue is that javassist itself did not understand things like

     

    @SomeAnnotation(clazz=org.blah.Something[])

     

    https://jira.jboss.org/jira/browse/JASSIST-111

    JBoss Reflect issue testing this and upgrading to javassist snapshot here http://jira.jboss.org/jira/browse/JBREFLECT-111

  • 2. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    I found some problems in the xml parsing since jbossxb invalidly assumed that to have actual type arguments the ClassInfo needs to be cast to ParameterizedClassInfo. The Javassist implementation does not use ParameterizedClassInfo

     

    https://jira.jboss.org/jira/browse/JBXB-245

  • 3. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    I am getting some failures in tests that have their own classloader when security is enabled, and am unsure where to put the privileged block? Initially I got this error:

     

    1545 ERROR [AbstractKernelController] Error installing to Instantiated: name=VFSBean1 state=Described

    java.lang.RuntimeException: java.security.PrivilegedActionException: javassist.CannotCompileException: by java.security.AccessControlExcepti

    on: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:296)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.createJavassistConstructor(JavassistMemberFactory.java:213)

    at org.jboss.reflect.plugins.javassist.JavassistReflectionFactory.createConstructor(JavassistReflectionFactory.java:108)

    at org.jboss.reflect.plugins.javassist.JavassistConstructorInfo.newInstance(JavassistConstructorInfo.java:146)

    at org.jboss.joinpoint.plugins.BasicConstructorJoinPoint.dispatch(BasicConstructorJoinPoint.java:81)

    at org.jboss.kernel.plugins.dependency.DispatchJoinPoint.run(DispatchJoinPoint.java:47)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:54)

    at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:125)

    at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:72)

    at org.jboss.kernel.plugins.dependency.InstantiateAction.installActionInternal(InstantiateAction.java:67)

    at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)

    at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:1)

    at org.jboss.dependency.plugins.action.SimpleControllerContextAction.secureInstallAction(SimpleControllerContextAction.java:67)

    at org.jboss.dependency.plugins.action.AccessControllerContextAction$1.run(AccessControllerContextAction.java:80)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:103)

    at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)

    at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:377)

    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044)

    at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083)

    at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322)

    at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246)

    at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139)

    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:894)

    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:641)

    at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:103)

    at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:97)

    at org.jboss.test.kernel.dependency.support.TestUtil.install(TestUtil.java:99)

    at org.jboss.test.kernel.dependency.test.OldAbstractKernelDependencyTest.install(OldAbstractKernelDependencyTest.java:112)

    at org.jboss.test.kernel.dependency.test.OldAbstractKernelDependencyTest.assertInstall(OldAbstractKernelDependencyTest.java:130)

    at org.jboss.test.kernel.dependency.test.OldAbstractKernelDependencyTest.assertInstall(OldAbstractKernelDependencyTest.java:123)

    at org.jboss.test.kernel.dependency.test.ConstructorClassLoaderTestCase.testConstructorClassLoaderReinstall(ConstructorClassLoaderTestCase.

    java:231)

    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:597)

    at junit.framework.TestCase.runTest(TestCase.java:168)

    at junit.framework.TestCase.runBare(TestCase.java:134)

    at junit.framework.TestResult$1.protect(TestResult.java:110)

    at junit.framework.TestResult.runProtected(TestResult.java:128)

    at junit.framework.TestResult.run(TestResult.java:113)

    at junit.framework.TestCase.run(TestCase.java:124)

    at junit.framework.TestSuite.runTest(TestSuite.java:232)

    at junit.framework.TestSuite.run(TestSuite.java:227)

    at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)

    at junit.extensions.TestSetup$1.protect(TestSetup.java:23)

    at junit.framework.TestResult.runProtected(TestResult.java:128)

    at junit.extensions.TestSetup.run(TestSetup.java:27)

    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)

    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Caused by: java.security.PrivilegedActionException: javassist.CannotCompileException: by java.security.AccessControlException: access denied

    (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:281)

    ... 55 more

    Caused by: javassist.CannotCompileException: by java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClass

    InPackage.sun.reflect)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:169)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:136)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory$1.run(JavassistMemberFactory.java:285)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory$1.run(JavassistMemberFactory.java:1)

    ... 57 more

    Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)

    at java.security.AccessController.checkPermission(AccessController.java:546)

    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

    at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1512)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)

    at org.jboss.test.classloading.vfs.VFSClassLoader.loadClass(VFSClassLoader.java:55)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)

    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:698)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:544)

    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at javassist.util.proxy.FactoryHelper.toClass2(FactoryHelper.java:181)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:163)

    ... 60 more

     

    I tried adding a privileged block to FactoryHelper, but still get the same error

     

    1545 ERROR [AbstractKernelController] Error installing to Instantiated: name=VFSBean1 state=Described

    java.lang.RuntimeException: java.security.PrivilegedActionException: javassist.CannotCompileException: by java.security.AccessControlExcepti

    on: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:296)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.createJavassistConstructor(JavassistMemberFactory.java:213)

    at org.jboss.reflect.plugins.javassist.JavassistReflectionFactory.createConstructor(JavassistReflectionFactory.java:108)

    at org.jboss.reflect.plugins.javassist.JavassistConstructorInfo.newInstance(JavassistConstructorInfo.java:146)

    at org.jboss.joinpoint.plugins.BasicConstructorJoinPoint.dispatch(BasicConstructorJoinPoint.java:81)

    at org.jboss.kernel.plugins.dependency.DispatchJoinPoint.run(DispatchJoinPoint.java:47)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.kernel.plugins.dependency.ExecutionWrapper.execute(ExecutionWrapper.java:54)

    at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchExecutionWrapper(KernelControllerContextAction.java:125)

    at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.dispatchJoinPoint(KernelControllerContextAction.java:72)

    at org.jboss.kernel.plugins.dependency.InstantiateAction.installActionInternal(InstantiateAction.java:67)

    at org.jboss.kernel.plugins.dependency.InstallsAwareAction.installAction(InstallsAwareAction.java:54)

    at org.jboss.kernel.plugins.dependency.KernelControllerContextAction.installAction(KernelControllerContextAction.java:1)

    at org.jboss.dependency.plugins.action.SimpleControllerContextAction.secureInstallAction(SimpleControllerContextAction.java:67)

    at org.jboss.dependency.plugins.action.AccessControllerContextAction$1.run(AccessControllerContextAction.java:80)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.dependency.plugins.action.AccessControllerContextAction.install(AccessControllerContextAction.java:103)

    at org.jboss.dependency.plugins.AbstractControllerContextActions.install(AbstractControllerContextActions.java:51)

    at org.jboss.dependency.plugins.AbstractControllerContext.install(AbstractControllerContext.java:377)

    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:2044)

    at org.jboss.dependency.plugins.AbstractController.incrementState(AbstractController.java:1083)

    at org.jboss.dependency.plugins.AbstractController.executeOrIncrementStateDirectly(AbstractController.java:1322)

    at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1246)

    at org.jboss.dependency.plugins.AbstractController.resolveContexts(AbstractController.java:1139)

    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:894)

    at org.jboss.dependency.plugins.AbstractController.install(AbstractController.java:641)

    at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:103)

    at org.jboss.kernel.plugins.dependency.AbstractKernelController.install(AbstractKernelController.java:97)

    at org.jboss.test.kernel.dependency.support.TestUtil.install(TestUtil.java:99)

    at org.jboss.test.kernel.dependency.test.OldAbstractKernelDependencyTest.install(OldAbstractKernelDependencyTest.java:112)

    at org.jboss.test.kernel.dependency.test.OldAbstractKernelDependencyTest.assertInstall(OldAbstractKernelDependencyTest.java:130)

    at org.jboss.test.kernel.dependency.test.OldAbstractKernelDependencyTest.assertInstall(OldAbstractKernelDependencyTest.java:123)

    at org.jboss.test.kernel.dependency.test.ConstructorClassLoaderTestCase.testConstructorClassLoaderReinstall(ConstructorClassLoaderTestCase.

    java:231)

    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:597)

    at junit.framework.TestCase.runTest(TestCase.java:168)

    at junit.framework.TestCase.runBare(TestCase.java:134)

    at junit.framework.TestResult$1.protect(TestResult.java:110)

    at junit.framework.TestResult.runProtected(TestResult.java:128)

    at junit.framework.TestResult.run(TestResult.java:113)

    at junit.framework.TestCase.run(TestCase.java:124)

    at junit.framework.TestSuite.runTest(TestSuite.java:232)

    at junit.framework.TestSuite.run(TestSuite.java:227)

    at junit.extensions.TestDecorator.basicRun(TestDecorator.java:24)

    at junit.extensions.TestSetup$1.protect(TestSetup.java:23)

    at junit.framework.TestResult.runProtected(TestResult.java:128)

    at junit.extensions.TestSetup.run(TestSetup.java:27)

    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:81)

    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)

    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)

    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)

    Caused by: java.security.PrivilegedActionException: javassist.CannotCompileException: by java.security.AccessControlException: access denied

    (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:281)

    ... 55 more

    Caused by: javassist.CannotCompileException: by java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClass

    InPackage.sun.reflect)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:169)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:136)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory$1.run(JavassistMemberFactory.java:285)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory$1.run(JavassistMemberFactory.java:1)

    ... 57 more

    Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)

    at java.security.AccessController.checkPermission(AccessController.java:546)

    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

    at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1512)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)

    at org.jboss.test.classloading.vfs.VFSClassLoader.loadClass(VFSClassLoader.java:55)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)

    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:698)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:544)

    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at javassist.util.proxy.SecurityActions$6.run(SecurityActions.java:124)

    at java.security.AccessController.doPrivileged(Native Method)

    at javassist.util.proxy.SecurityActions.invokeMethod(SecurityActions.java:121)

    at javassist.util.proxy.FactoryHelper.toClass2(FactoryHelper.java:181)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:163)

     

    Is there any way around this other than adding a properties file for the test containing the permission?

  • 4. Re: Issues using Javassist TypeInfoFactory in other projects
    Anil Saldhana Master

    I would probably start here:

    =================================

    on: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:296)

    at

    ======================

     

    Place a privileged block.

  • 5. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    ANIL SALDHANA wrote:

     

    I would probably start here:

    =================================

    on: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:296)

    at

    ======================

     

    Place a privileged block.

    That line is just a rethrow from a catch block:

     

             final ClassLoader cl = target.getClassPool().getClassLoader();
    
             return AccessController.doPrivileged(new PrivilegedExceptionAction<Class<T>>() //Line 281
             {
                public Class<T> run() throws Exception
                {
                   return FactoryHelper.toClass(cf, cl); //Line 285
                }
             });
    
          }
          catch(RuntimeException e)
          {
             throw e;
          }
          catch (Exception e)
          {
             throw new RuntimeException(e); //Line 296
          }
       }
    

     

    the real work is done here:

     

    Caused by: java.security.PrivilegedActionException: javassist.CannotCompileException: by java.security.AccessControlException: access denied

    (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at java.security.AccessController.doPrivileged(Native Method)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory.makeClass(JavassistMemberFactory.java:281)

    ... 55 more

    Caused by: javassist.CannotCompileException: by java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClass

    InPackage.sun.reflect)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:169)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:136)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory$1.run(JavassistMemberFactory.java:285)

    at org.jboss.reflect.plugins.javassist.bytecode.JavassistMemberFactory$1.run(JavassistMemberFactory.java:1)

    <SNIP/>

    Caused by: java.security.AccessControlException: access denied (java.lang.RuntimePermission accessClassInPackage.sun.reflect)

    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:323)

    at java.security.AccessController.checkPermission(AccessController.java:546)

    at java.lang.SecurityManager.checkPermission(SecurityManager.java:532)

    at java.lang.SecurityManager.checkPackageAccess(SecurityManager.java:1512)

    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:327)

    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)

    at org.jboss.test.classloading.vfs.VFSClassLoader.loadClass(VFSClassLoader.java:55)   <---

    at java.lang.ClassLoader.loadClass(ClassLoader.java:250)

    at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:398)

    at java.lang.ClassLoader.defineClass1(Native Method)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:698)

    at java.lang.ClassLoader.defineClass(ClassLoader.java:544)

    at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

    at java.lang.reflect.Method.invoke(Method.java:597)

    at javassist.util.proxy.SecurityActions$6.run(SecurityActions.java:124)

    at java.security.AccessController.doPrivileged(Native Method)

    at javassist.util.proxy.SecurityActions.invokeMethod(SecurityActions.java:121)

    at javassist.util.proxy.FactoryHelper.toClass2(FactoryHelper.java:182)

    at javassist.util.proxy.FactoryHelper.toClass(FactoryHelper.java:163)

     

    I'm not 100% sure, but the marked line would probably be the right place to put it, however that might be a security violation?

  • 6. Re: Issues using Javassist TypeInfoFactory in other projects
    Anil Saldhana Master

    Have you tried providing the perms to "org.jboss.test.classloading.vfs.VFSClassLoader.loadClass" in your policy file? That is the root of the problem here.

  • 7. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    ANIL SALDHANA wrote:

     

    Have you tried providing the perms to "org.jboss.test.classloading.vfs.VFSClassLoader.loadClass" in your policy file? That is the root of the problem here.

    Yeah, I've played with that, and that seems to work fine. The tests failing already had a policy file, just missing this permission (for my new stuff), so I assume this is ok.

  • 8. Re: Issues using Javassist TypeInfoFactory in other projects
    Anil Saldhana Master

    Yeah from the stack trace, I can say that your test class that is loading the class needs to have the permission.

  • 9. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    Some tests needed updating to understand classloaders when using the javassist type infos. Basially adding a bean that is a reflect ClassPoolFactory implementation, which has in/uncallback listeners for classloaders: https://jira.jboss.org/jira/browse/JBREFLECT-107

  • 10. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    Another issue is that dynamically created classes are not found in the classpools.

     

    Dynamic proxies are not found at all:

    0 DEBUG [JDKLazyInstantiationTestCase] ==== setUp org.jboss.test.kernel.lazy.test.JDKLazyInstantiationTestCase ====

    5 DEBUG [JDKLazyInstantiationTestCase] ==== Starting testLazy ====

    20 DEBUG [KernelFactory] Starting JBoss Kernel construction...

    53 WARN  [PropertyConfiguration] Factory: org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory@4393722c

    466 DEBUG [KernelFactory] Completed JBoss Kernel construction.  Duration: 446 milliseconds

    568 ERROR [AbstractKernelController] Error installing to Instantiated: name=beanProxy state=Described

    java.lang.RuntimeException: Class not found: $Proxy0

    at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.get(JavassistTypeInfoFactoryImpl.java:311)

    at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.getTypeInfo(JavassistTypeInfoFactoryImpl.java:519)

    at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory.getTypeInfo(JavassistTypeInfoFactory.java:51)

    at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapter(BasicClassAdapterFactory.java:54)

     

     

    Neither are the javassist ProxyFactory proxies, since they just define the class in the classloader with no way to find them from the pools:

    0 DEBUG [JavassistLazyInstantiationTestCase] ==== setUp org.jboss.test.kernel.lazy.test.JavassistLazyInstantiationTestCase ====

    3 DEBUG [JavassistLazyInstantiationTestCase] ==== Starting testLazy ====

    18 DEBUG [KernelFactory] Starting JBoss Kernel construction...

    47 WARN  [PropertyConfiguration] Factory: org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory@4393722c

    514 DEBUG [KernelFactory] Completed JBoss Kernel construction.  Duration: 496 milliseconds

    618 ERROR [AbstractKernelController] Error installing to Instantiated: name=beanProxy state=Described

    java.lang.RuntimeException: Class not found: org.jboss.test.kernel.lazy.support.IRare_$$_javassist_0

    at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.get(JavassistTypeInfoFactoryImpl.java:311)

    at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactoryImpl.getTypeInfo(JavassistTypeInfoFactoryImpl.java:519)

    at org.jboss.reflect.plugins.javassist.JavassistTypeInfoFactory.getTypeInfo(JavassistTypeInfoFactory.java:51)

    at org.jboss.classadapter.plugins.BasicClassAdapterFactory.getClassAdapter(BasicClassAdapterFactory.java:54)

     

    In AOP what we did was to write the class bytes to the in memory vfs location from the aop classpools, so that when trying to look up the CtClass later there is a resource path for the class bytes:

             URL outputURL = new URL(tempURL.toString() + "/" + classFileName);
             //Write the classfile to the temporary url
             synchronized (tmplock)
             {
                if (trace) logger.trace(this + " " + pool + ".toClass() myloader:" + myloader + " writing bytes to " + tempURL);
                ByteArrayOutputStream byteout = new ByteArrayOutputStream();
                BufferedOutputStream out = new BufferedOutputStream(byteout);
                out.write(cc.toBytecode());
                out.flush();
                out.close();
    
                byte[] classBytes = byteout.toByteArray();
                MemoryContextFactory factory = MemoryContextFactory.getInstance();
                factory.putFile(outputURL, classBytes);
    

     

    Going to check with Chiba, but I'll see if I can modify javassist to allow ProxyFactory and ProxyFactoryHelper to accept an interface like

     

    interface ByteRecorder{
       void writeBytes(String classname, byte[]) throws IOException
    }
    

     

     

     

  • 11. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    I am also seeing this

     

    java.lang.IllegalArgumentException: Cannot set accessible on method info: JavassistMethodInfo@5578920a{name=privMain}
    at org.jboss.test.kernel.deployment.support.StaticInjector.injectToMethod(StaticInjector.java:76)
    at org.jboss.test.kernel.deployment.support.StaticInjector.injectToNonPublicMethod(StaticInjector.java:59)
    at org.jboss.test.kernel.deployment.test.BeanContainerStaticTestCase.testStaticInjection(BeanContainerStaticTestCase.java:53)

     

       private void injectToMethod(Class<?> clazz, String method, Object value, Class<?> signature, boolean isPublic) throws Throwable
       {
          ClassInfo classInfo = configurator.getClassInfo(clazz);
          MethodInfo mi = Config.findMethodInfo(classInfo, method, new String[]{signature.getName()}, true, isPublic);
          if (isPublic == false)
          {
             // TODO - move this into Reflection?
             if (mi instanceof ReflectMethodInfoImpl)
             {
                ReflectMethodInfoImpl rmi = (ReflectMethodInfoImpl)mi;
                Method  m = rmi.getMethod();
                m.setAccessible(true);
             }
             else
                throw new IllegalArgumentException("Cannot set accessible on method info: " + mi);
          }
          mi.invoke(null, new Object[]{value});
       }
    
    If we moved the setAccessible() stuff to jboss-reflect as indicated in the comment, we could manage the accessibility of members there?

  • 12. Re: Issues using Javassist TypeInfoFactory in other projects
    Ales Justin Master

    If we moved the setAccessible() stuff to jboss-reflect as indicated in the comment, we could manage the accessibility of members there?

    This was a hack to get private method injection working -- use case for some EJB sandbox/prototype.

    Dunno if this is still needed, perhaps just check if BeanAccessMode.ALL already does this on top of BeanInfo.

    I know it does for private method/fields, just not sure about any method.

    If not, then we can simply extend this notion of ALL to methods as well.

  • 13. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    It looks like ReflectMethodImpl.setMethod() and ReflectFieldImpl.setField() do that already:

    RMI:

       public void setMethod(Method method)
       {
          boolean isDeclaringClassPublic = true;
          if (method != null)
          {
             accessCheck(Modifier.isPublic(method.getModifiers()));
             isDeclaringClassPublic = isDeclaringClassPublic(method);
             accessCheck(isDeclaringClassPublic);
          }
    
          this.method = method;
    
          if (method != null && (isPublic() == false || isDeclaringClassPublic == false))
             setAccessible();
       }
    

     

    RFI:

       public void setField(Field field)
       {
          if (field != null)
             accessCheck(Modifier.isPublic(field.getModifiers()));
    
          this.field = field;
    
          if (isPublic() == false && field != null)
             setAccessible();
       }
    

     

    Commenting out the whole block which threw the exception for JavassistMethodInfo, and setAccessible=true for ReflectMethodInfoImpl, works with both modes

     

    org.jboss.test.kernel.deployment.support.StaticInjector:

     

       private void injectToMethod(Class<?> clazz, String method, Object value, Class<?> signature, boolean isPublic) throws Throwable
       {
          ClassInfo classInfo = configurator.getClassInfo(clazz);
          MethodInfo mi = Config.findMethodInfo(classInfo, method, new String[]{signature.getName()}, true, isPublic);
    //      if (isPublic == false)
    //      {
    //         // TODO - move this into Reflection?
    //         if (mi instanceof ReflectMethodInfoImpl)
    //         {
    //            ReflectMethodInfoImpl rmi = (ReflectMethodInfoImpl)mi;
    //            Method  m = rmi.getMethod();
    //            m.setAccessible(true);
    //         }
    //         else
    //            throw new IllegalArgumentException("Cannot set accessible on method info: " + mi);
    //      }
          mi.invoke(null, new Object[]{value});
       }
    

     

     

  • 14. Re: Issues using Javassist TypeInfoFactory in other projects
    Kabir Khan Master

    Kabir Khan wrote:

     

    Another issue is that dynamically created classes are not found in the classpools.

     

    Rather than all the fancy BytecodeRecorder stuff, I am simply delegating to the IntrospectionTypeInfoFactory if the class can not be found in the classpool:

     

     

    [kabir ~/sourcecontrol/jboss-reflect/trunk/jboss-reflect]
    $svn diff
    Index: src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java
    ===================================================================
    --- src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java     (revision 103127)
    +++ src/main/java/org/jboss/reflect/plugins/javassist/JavassistTypeInfoFactoryImpl.java     (working copy)
    @@ -49,6 +49,7 @@
     import org.jboss.reflect.plugins.AnnotationValueImpl;
     import org.jboss.reflect.plugins.EnumConstantInfoImpl;
     import org.jboss.reflect.plugins.GenericsUtil;
    +import org.jboss.reflect.plugins.introspection.IntrospectionTypeInfoFactory;
     import org.jboss.reflect.plugins.javassist.classpool.ClassPoolFactory;
     import org.jboss.reflect.plugins.javassist.classpool.DefaultClassPoolFactory;
     import org.jboss.reflect.spi.AnnotationInfo;
    @@ -284,11 +285,33 @@
           }
           catch(NotFoundException nfe)
           {
    -         throw new ClassNotFoundException(nfe.getMessage());
    +         return delegateToIntrospectionImplementation(cl, name);
           }
        }
        
        /**
    +    * Proxies, whether
    +    * <ul>
    +    * <li>JDK dynamic proxies</li>
    +    * <li>javassist ProxyFactory proxies - created by calling ClassLoader.defineClass()</li>
    +    * </ul> 
    +    * are not visible to the javassist classpools, and neither will classes generated by cglib or other
    +    * frameworks, so try to load up the class from the reflect implementation.
    +    * 
    +    * @param cl the classloader
    +    * @param name the name of the class
    +    * @return the info
    +    * @throws ClassNotFoundException when the class cannot be found
    +    */
    +   private TypeInfo delegateToIntrospectionImplementation(ClassLoader cl, String name) throws ClassNotFoundException
    +   {
    +      //Check the class has been loaded
    +      cl.loadClass(name);
    +      IntrospectionTypeInfoFactory factory = new IntrospectionTypeInfoFactory();
    +      return factory.getTypeInfo(name, cl);
    +   }
    +   
    +   /**
    
1 2 Previous Next