Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
guan-kevin opened this issue Jul 18, 2024 · 6 comments
Open

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

guan-kevin opened this issue Jul 18, 2024 · 6 comments
Assignees

Comments

@guan-kevin
Copy link

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?

@kriegaex
Copy link
Contributor

kriegaex commented Jul 18, 2024

Maybe this is somehow similar or related to #285. I can reproduce this behaviour back until at least 1.8.13, i.e. it is not a new thing and dates back to when I was just a simple AspectJ user, not a contributor to the project yet.

Judging from this test configuration file, not using aj.weaving.cache.impl at all defaults to aj.weaving.cache.impl=perloader, which seems to be correct according to my quick experiments. If the cache ever worked for that case when used repeatedly and "just" broke a long time ago or if it never worked to begin with, is yet to be established. I admit that I never use the weaving cache myself, so I need to dig into this at some point. This is just my first feedback.

kriegaex added a commit that referenced this issue Jul 18, 2024
by refining and extending org.aspectj.systemtest.ajc171.NewFeatures,
also considering around advice types and repeated weaving, actually
re-using the cache.

Signed-off-by: Alexander Kriegisch <[email protected]>
@kriegaex kriegaex self-assigned this Jul 18, 2024
@kriegaex
Copy link
Contributor

Please note my recent message to the aspectj-users and aspectj-announce mailing lists regarding my situation as an AspectJ maintainer.

@oakkitten
Copy link

Not sure if related, but I'm getting this:

Caused by: java.lang.NoClassDefFoundError: org.aspectj.runtime.reflect.JoinPointImpl$$ExternalSyntheticLambda0
    at org.aspectj.runtime.reflect.JoinPointImpl.<init>(JoinPointImpl.java:145)
    at org.aspectj.runtime.reflect.Factory.makeJP(Factory.java:270)

after upgrading from 1.9.21 to either 1.9.22 or 1.9.22.1, on Android 23 emulator and below. 24+ seems to be alright.

@kriegaex
Copy link
Contributor

@oakkitten, at first glance, this seems to be unrelated, because an AspectJ class does not seem to be found rather than a generated one. The $$ExternalSyntheticLambda0 bit seems to be an Android-specific thing, but not being an Android developer I have no idea what it is about. The fact that it seems to work in one version of Android studio but not in another sounds as if it could be a configuration issue, but I have no way to be sure. If you think that this is an AspectJ issue, please prepare a minimal reproducer and attach it to a new issue. Thank you.

@oakkitten
Copy link

oakkitten commented Nov 17, 2024

If I get around to investigating, I will. However, AspectJ on Android seems to very rarely used, especially because of how increasingly hard it has became to plug weaving into the build pipeline. So perhaps it's just not worth the effort. Said that, 1.9.21 works fine, so maybe I can try bisecting at least. Will open a new issue if I find anything.

(P.S. It's not different Android Studio versions, but different Android emulator versions, which run different versions of SDK API and Java API. Android 23 is quite old, from 2015)

@kriegaex
Copy link
Contributor

kriegaex commented Nov 18, 2024

If I get around to investigating, I will.

If you are interested in a future solution, it would be helpful for you to get around to it. Thanks.

However, AspectJ on Android seems to very rarely used

I have no idea. All I know is that over the years I have answered multiple questions about related problems on Stack Overflow, and actually the problem was never AspectJ as such but rather its configuration, as far as I remember. Some people do seem to use it.

especially because of how increasingly hard it has became to plug weaving into the build pipeline.

Is that so? I really have no idea. Is there anything the AspectJ project can or should do about it, or is that rather a problem of complex tooling in the Android build pipeline with Gradle or Maven?

1.9.21 works fine, so maybe I can try bisecting at least.

Well, but you also said that 1.9.22.x seems to be problematic on certain emulator versions, not on others, including the latest one. So, the bisection result might point to a related AspectJ change making the emulator run out of whack in v23, but if it works again in v24, maybe it is really an emulator problem rather than an AspectJ one. But this is, of course, speculation.

Will open a new issue if I find anything.

Thank you so much, I appreciate your future input.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants