ExceptionInInitializerError in LTW

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

ExceptionInInitializerError in LTW

Andrey Semenyuk
Hello all,

I try to complete LTW example from AspectJ Cookbook, but it doesn't work.
I created and compiled Java class:

public class MyClass{
        public void foo(int number, String name){
                System.out.println("Inside of foo");
        }

        public static void main(String[] args) {
                MyClass myObject = new MyClass();
                myObject.foo(1, "Str");
        }
}

it works just fine:

c:\TEMP\examples>java MyClass
Inside of foo

Then I created aspect:

public aspect HelloWorld{
        pointcut callPointcut(): call(void MyClass.foo(int, String));

        before() : callPointcut(){
                System.out.println("Hello World from advice");
        }
}

compiled it:

c:\TEMP\examples>c:\tools\aspectj1.8\bin\ajc -outjar my.jar HelloWorld.aj
C:\TEMP\examples\HelloWorld.aj:4 [warning] no match for this type name: MyClass [Xlint:invalidAbsoluteTypeName]
pointcut callPointcut(): call(void MyClass.foo(int, String));
                                   ^^^^^^^^^
        [Xlint:invalidAbsoluteTypeName]

1 warning

And then try to run:

    c:\TEMP\examples>java -classpath "C:\tools\aspectj1.8\lib\aspectjweaver.jar" "-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader" -Daj.class.path=. "-Daj.aspect.path=c:\TEMP\examples" MyClass
    java.lang.ExceptionInInitializerError
            at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
            at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
            at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
            at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
            at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
            at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
    Caused by: java.lang.IllegalStateException: recursive invocation
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
            at java.util.ServiceLoader.loadInstalled(Unknown Source)
            at java.util.ResourceBundle.<clinit>(Unknown Source)
            ... 17 more
    Error occurred during initialization of VM
    java.lang.ExceptionInInitializerError
            at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
            at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
            at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
            at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
            at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
            at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
    Caused by: java.lang.IllegalStateException: recursive invocation
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
            at java.util.ServiceLoader.loadInstalled(Unknown Source)
            at java.util.ResourceBundle.<clinit>(Unknown Source)
            at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
            at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
            at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
            at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
            at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
            at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)

I try different solutions and exception occurs only if I provide -Daj.aspect.path=c:\TEMP\examples, but as far as I understand it is because weaver will load aspect only of this option is provided. Without this option Java program works without any aspects weaved at load time.

--
Best regards,
Andrey
_______________________________________________
aspectj-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: ExceptionInInitializerError in LTW

Andy Clement
I don't tend to run LTW like that, I use the agent - I think that's what we recommend.  I just ran your code ok:

javac MyClass.java

ajc HelloWorld.java -1.8 -outxml -d out

export CLASSPATH=.:out:$CLASSPATH

java -javaagent:$AJHOME/lib/aspectjweaver.jar MyClass
Hello World from advice
Inside of foo

Are you ok with using the agent?  The -outxml line on the ajc call is what produces the META-INF/aop-ajc.xml file in the out folder, and that is what the agent will look for to turn on weaving. (That xml file will simply list the aspects to 'turn on')

cheers,
Andy

On 22 January 2016 at 00:34, Andrey Semenyuk <[hidden email]> wrote:
Hello all,

I try to complete LTW example from AspectJ Cookbook, but it doesn't work.
I created and compiled Java class:

public class MyClass{
        public void foo(int number, String name){
                System.out.println("Inside of foo");
        }

        public static void main(String[] args) {
                MyClass myObject = new MyClass();
                myObject.foo(1, "Str");
        }
}

it works just fine:

c:\TEMP\examples>java MyClass
Inside of foo

Then I created aspect:

public aspect HelloWorld{
        pointcut callPointcut(): call(void MyClass.foo(int, String));

        before() : callPointcut(){
                System.out.println("Hello World from advice");
        }
}

compiled it:

c:\TEMP\examples>c:\tools\aspectj1.8\bin\ajc -outjar my.jar HelloWorld.aj
C:\TEMP\examples\HelloWorld.aj:4 [warning] no match for this type name: MyClass [Xlint:invalidAbsoluteTypeName]
pointcut callPointcut(): call(void MyClass.foo(int, String));
                                   ^^^^^^^^^
        [Xlint:invalidAbsoluteTypeName]

1 warning

And then try to run:

    c:\TEMP\examples>java -classpath "C:\tools\aspectj1.8\lib\aspectjweaver.jar" "-Djava.system.class.loader=org.aspectj.weaver.loadtime.WeavingURLClassLoader" -Daj.class.path=. "-Daj.aspect.path=c:\TEMP\examples" MyClass
    java.lang.ExceptionInInitializerError
            at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
            at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
            at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
            at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
            at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
            at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
    Caused by: java.lang.IllegalStateException: recursive invocation
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
            at java.util.ServiceLoader.loadInstalled(Unknown Source)
            at java.util.ResourceBundle.<clinit>(Unknown Source)
            ... 17 more
    Error occurred during initialization of VM
    java.lang.ExceptionInInitializerError
            at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
            at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
            at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
            at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
            at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
            at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
    Caused by: java.lang.IllegalStateException: recursive invocation
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)
            at java.util.ServiceLoader.loadInstalled(Unknown Source)
            at java.util.ResourceBundle.<clinit>(Unknown Source)
            at org.aspectj.weaver.WeaverMessages.<clinit>(WeaverMessages.java:18)
            at org.aspectj.weaver.bcel.ClassPathManager.addPath(ClassPathManager.java:81)
            at org.aspectj.weaver.bcel.ClassPathManager.<init>(ClassPathManager.java:63)
            at org.aspectj.weaver.bcel.BcelWorld.<init>(BcelWorld.java:285)
            at org.aspectj.weaver.tools.WeavingAdaptor.init(WeavingAdaptor.java:176)
            at org.aspectj.weaver.tools.WeavingAdaptor.<init>(WeavingAdaptor.java:109)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:75)
            at org.aspectj.weaver.loadtime.WeavingURLClassLoader.<init>(WeavingURLClassLoader.java:52)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
            at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
            at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
            at java.lang.reflect.Constructor.newInstance(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.lang.SystemClassLoaderAction.run(Unknown Source)
            at java.security.AccessController.doPrivileged(Native Method)
            at java.lang.ClassLoader.initSystemClassLoader(Unknown Source)
            at java.lang.ClassLoader.getSystemClassLoader(Unknown Source)

I try different solutions and exception occurs only if I provide -Daj.aspect.path=c:\TEMP\examples, but as far as I understand it is because weaver will load aspect only of this option is provided. Without this option Java program works without any aspects weaved at load time.

--
Best regards,
Andrey
_______________________________________________
aspectj-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users


_______________________________________________
aspectj-users mailing list
[hidden email]
To change your delivery options, retrieve your password, or unsubscribe from this list, visit
https://dev.eclipse.org/mailman/listinfo/aspectj-users
Loading...