6 Replies Latest reply on May 11, 2005 10:25 PM by twundke

    Retain ProtectionDomain for instrumented classes

    twundke

      I'm using runtime AOP as a part of JBoss Cache. This is all contained within a standalone application that uses custom class loaders and custom ProtectionDomain objects. The problem that I'm seeing is that AOP-generated classes lose their associated protection domain, which in my case contains various additional fields that my application requires.

      This problem is easy to verify as AspectManager.transform doesn't pass on the ProtectionDomain object when calling the translate method. The protection domain is simply lost.

      Would it be possible to assign to the transformed class the same protection domain object as the original class?

      Thanks.

      Tim.

        • 1. Re: Retain ProtectionDomain for instrumented classes
          starksm64

          File a bug report as we cannot be throwing away the protection domain.
          http://jira.jboss.com/jira/browse/JBAOP

          • 2. Re: Retain ProtectionDomain for instrumented classes
            bill.burke

            This is not true. The ClassLoader creates the class and it has the ProtectionDomain. A special ProtectionDomain is created for dynamically created classes though.

            • 3. Re: Retain ProtectionDomain for instrumented classes
              starksm64

              Give a concrete example that illustrates where the PD is getting lost then Tim.

              • 4. Re: Retain ProtectionDomain for instrumented classes
                twundke

                Sorry I wasn't clearer in my original post. It's been a while since I looked at this issue.

                My particular problem is that the generated field wrapper inner classes don't get assigned the correct protection domain. Here's a stack trace that shows the problem occuring.

                 getDefaultDomain():1583, ClassLoader.java
                 preDefineClass():483, ClassLoader.java
                 defineClass():614, ClassLoader.java
                 defineClass():465, ClassLoader.java
                 invoke0():-1, NativeMethodAccessorImpl.java
                 invoke():39, NativeMethodAccessorImpl.java
                 invoke():25, DelegatingMethodAccessorImpl.java
                 invoke():585, Method.java
                 toClass():52, StandaloneClassPool.java
                 toClass():962, CtClass.java
                 compileOrLoadClass():119, TransformerCommon.java
                 createOptimizedInvocationClass():572, FieldAccessTransformer.java
                 buildOptimizedReadWrapper():358, FieldAccessTransformer.java
                 buildOptimizedWrappers():342, FieldAccessTransformer.java
                 buildFieldWrappers():232, FieldAccessTransformer.java
                 buildFieldWrappers():65, FieldAccessTransformer.java
                 transform():592, Instrumentor.java
                 translate():572, AspectManager.java
                 transform():490, AspectManager.java
                 aspectTransform():100, AopAgent.java
                 transform():141, AopAgent.java
                 transform():122, TransformerManager.java
                 transform():155, InstrumentationImpl.java
                 defineClass1():-1, ClassLoader.java
                 defineClass():620, ClassLoader.java
                 defineClass():320, BaseURLClassLoader.java
                 access$000():38, BaseURLClassLoader.java
                 run():108, BaseURLClassLoader.java
                 run():98, BaseURLClassLoader.java
                 doPrivileged():-1, AccessController.java
                 findClass():96, BaseURLClassLoader.java
                 findClassInternal():168, BaseClassLoader.java
                 findClassInternal():146, BaseClassLoader.java
                 findClassInternal():49, FrameworkClassLoader.java
                 loadClass():280, BaseClassLoader.java
                 loadClass():251, ClassLoader.java
                 loadClassInternal():319, ClassLoader.java
                 initialiseDomains():117, DomainManagerImpl.java
                 <init>():78, DomainManagerImpl.java
                 start():153, FrameworkController.java
                 invoke0():-1, NativeMethodAccessorImpl.java
                 invoke():39, NativeMethodAccessorImpl.java
                 invoke():25, DelegatingMethodAccessorImpl.java
                 invoke():585, Method.java
                 initialiseFramework():366, FrameworkLoader.java
                 main():463, FrameworkLoader.java
                


                The toClass method of StandaloneClassPool does the following:
                 Class cl = Class.forName("java.lang.ClassLoader");
                 java.lang.reflect.Method method
                 = cl.getDeclaredMethod("defineClass",
                 new Class[]{String.class, byte[].class,
                 int.class, int.class});
                


                My classloader doesn't get a chance to define the class, causing the field wrappers to be assigned a default protection domain.

                So, what's actually needed is for the class pool to use the correct classloader when calling defineClass.

                Hope that helps.

                Tim.

                • 5. Re: Retain ProtectionDomain for instrumented classes
                  starksm64

                  The following issue has been created to validate or reject this:
                  http://jira.jboss.com/jira/browse/JBAOP-126

                  • 6. Re: Retain ProtectionDomain for instrumented classes
                    twundke

                    Thanks Scott. I'm happy to help with the implementation of the fix if needed.

                    Tim.