Skip to content

Bug? NoClassDefFoundError when using around advice and LTW cache #314

Open
@guan-kevin

Description

in src/MyAspect.aj

public aspect MyAspect {
    before() : call(void Foo.bar()) {
        System.out.println("before bar");
    }

    void around(): call(void Foo.bar()) {
        System.out.println("around bar");
        proceed();
    }
}

In src/foo.java

class Foo {
    public void bar() {
        System.out.println("inside bar");
    }
    public static void main(String[] args) {
        Foo f = new Foo();
        f.bar();
    }
}

In classes/META-INF/aop.xml

<aspectj>
    <aspects>
        <aspect name="MyAspect"/>
    </aspects>
    <weaver options="-verbose">
    </weaver>
</aspectj>

Running the command

java -javaagent:path/to/aspectjweaver.jar -Dorg.aspectj.weaver.showWeaveInfo=true -Daj.weaving.cache.enabled=true -Daj.weaving.cache.dir=/tmp/aspectj-cache/ -cp classes Foo

twice will lead to the following error

Error: Unable to initialize main class Foo
Caused by: java.lang.NoClassDefFoundError: Foo$AjcClosure1

However, if I set cache implementation to shared, then it will work as expected:

java -javaagent:path/to/aspectjweaver.jar -Dorg.aspectj.weaver.showWeaveInfo=true -Daj.weaving.cache.enabled=true -Daj.weaving.cache.dir=/tmp/aspectj-cache/ -Daj.weaving.cache.impl=shared -cp classes Foo

Is this a bug? And what does this -Daj.weaving.cache.impl=shared shared implementation option do?

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions