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

LTW via OSGi in Eclipse 2024-03 plugins is not working #57

Closed
urferr opened this issue Apr 2, 2024 · 48 comments
Closed

LTW via OSGi in Eclipse 2024-03 plugins is not working #57

urferr opened this issue Apr 2, 2024 · 48 comments
Assignees
Labels
bug Something isn't working

Comments

@urferr
Copy link

urferr commented Apr 2, 2024

We use an aspectj plugin to weave some classes in the eclipse IDE. This was working fine until eclipse 2023-12 but now with eclipse 2024-03 its failing. I have also installed the latest version of AJDT but this did not solve the problem. For all the classes there exists an aspect for we get now the following error:

eclipse.buildId=4.31.0.I20240229-0520
java.version=21.0.1
java.vendor=Eclipse Adoptium
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=de_CH
Command-line arguments:  -os win32 -ws win32 -arch x86_64

org.eclipse.buildship.core
Error
Tue Apr 02 10:59:34 CEST 2024
Project import failed due to an unexpected error.

java.lang.NoClassDefFoundError: org/eclipse/core/internal/resources/ProjectDescription$AjcClosure1
	at org.eclipse.core.internal.resources.ProjectDescription.setNatureIds(ProjectDescription.java:852)
	at org.eclipse.buildship.core.internal.workspace.DefaultWorkspaceOperations.addNature(DefaultWorkspaceOperations.java:219)
	at org.eclipse.buildship.core.internal.workspace.ImportRootProjectOperation.importRootProject(ImportRootProjectOperation.java:105)
	at org.eclipse.buildship.core.internal.workspace.ImportRootProjectOperation$1.run(ImportRootProjectOperation.java:68)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2448)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2468)
	at org.eclipse.buildship.core.internal.workspace.ImportRootProjectOperation.runInWorkspace(ImportRootProjectOperation.java:58)
	at org.eclipse.buildship.core.internal.workspace.ImportRootProjectOperation.run(ImportRootProjectOperation.java:51)
	at org.eclipse.buildship.core.internal.DefaultGradleBuild$SynchronizeOperation.runInToolingApi(DefaultGradleBuild.java:230)
	at org.eclipse.buildship.core.internal.operation.DefaultToolingApiOperationManager$WorkspaceRunnableAdapter.run(DefaultToolingApiOperationManager.java:58)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2448)
	at org.eclipse.core.internal.resources.Workspace.run(Workspace.java:2473)
	at org.eclipse.buildship.core.internal.operation.DefaultToolingApiOperationManager.run(DefaultToolingApiOperationManager.java:39)
	at org.eclipse.buildship.core.internal.DefaultGradleBuild$SynchronizeOperation.run(DefaultGradleBuild.java:197)
	at org.eclipse.buildship.core.internal.DefaultGradleBuild.synchronize(DefaultGradleBuild.java:105)
	at org.eclipse.buildship.ui.internal.wizard.project.ProjectImportWizardController$5.run(ProjectImportWizardController.java:213)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:124)
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.internal.resources.ProjectDescription$AjcClosure1 cannot be found by org.eclipse.core.resources_3.20.100.v20240209-1706
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:562)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:557)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:434)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:174)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:526)
	... 17 more

For me this looks like classes are not generated by the loadtime weaver.

@urferr urferr changed the title loadtime weaving seems not to work in eclipse 2400-03 loadtime weaving seems not to work in eclipse 2024-03 Apr 2, 2024
@kriegaex kriegaex self-assigned this Apr 2, 2024
@kriegaex kriegaex added the question Further information is requested label Apr 2, 2024
@urferr
Copy link
Author

urferr commented Apr 2, 2024 via email

@kriegaex
Copy link
Contributor

kriegaex commented Apr 2, 2024

Then please, publish a minimal reproducer on GitHub. I cannot debug what I cannot see, compile and run.

@k-mierzej
Copy link

k-mierzej commented Apr 3, 2024

Hi, I will join your report as I have similar issue. I've described my problem on stackoverflow if you want to see it.

Here is the example Eclipse product which can be build by maven mvn package (it needs maven 3.9+ if I remember correctly). During launch of the application, NoClassDefFoundError exception is thrown.

example.zip

Oh, and by the way, this issue only affects windows platform, its working fine on my Kubuntu distro.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

During launch of the application, NoClassDefFoundError exception is thrown.

How do I launch the application? I built the project from the command line successfully. Now, what are the next steps? Warning: I am unexperienced in all things Tycho, Eclipse plugins and OSGi. It might surprise you, but I only use as much of these as is minimally necessary to compile AJDT. I actually have no idea how they work. So please, tell me what to do to reproduce the problem.

Update: I also do not know how to correctly import the project into Eclipse. Normally, I do not use Eclipse.

@k-mierzej
Copy link

k-mierzej commented Apr 3, 2024

Sorry, I forgot to specify all the steps required to reproduce the issue.

If maven build is finished, you should have the eclipse application built in following directories:
./example-ide/target/products/com.example.ide.product/linux/gtk/x86_64/
./example-ide/target/products/com.example.ide.product/win32/win32/x86_64/

And then if you open the Error Log view (Window -> Show View -> Error Log) there is the error shown.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

Yeah, I see it. But sorry, how am I supposed to debug this? The application is complex (it seems to be a customised Eclipse IDE or some kind of RCP application of size ~320 MB. I have no idea where to start looking for the root cause of the problem. I also cannot see where and how LTW is used there. Don't you have a small example project which I can simply run from an existing Eclipse 2024-03 IDE installation? It is intransparent to me what is going on under the hood here.

You also seem to use org.codehaus.mojo:aspectj-maven-plugin:1.15.0, which by default uses AspectJ 1.9.7 to stay compatible with build environment JDK 8. In your configuration, you do not seem to upgrade the plugin dependency to aspectjtools to the current 1.9.22, which is the one containing the JDT Core API changes present in Eclipse 2024-03. Maybe this also influences the outcome, maybe not. BTW, I recommend dev.aspect:aspectj-maven-plugin:1.14 instead, even though here probably it is not connected to the problem.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

Upgrading the plugin dependency to aspectjtools:1.9.22 is not helping. I am having trouble to see where AspectJ LTW is used here at all. In the stack trace, I only see Eclipse OSGi stuff, not a single line of AspectJ code is in the stack trace. Furthermore, you seem to be using compile-time weaving, not load-time weaving. Sorry, I am confused. I can only say that I tried a few LTW configurations in Eclipse, and they work fine.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

Note to myself

One possible problem source could be the fact that Eclipse IDE (and with it our dependency JDT Core) is released before the support for the next Java version is merged to the main branch, e.g. https://github.com/eclipse-jdt/eclipse.jdt.core/commits/R4_31/ from Feb-17. I.e., AspectJ, being urged by its users to always support the latest Java version but also the latest Eclipse version, always merges later commits, typically right after the new Java beta branch has been merged into the JDT Core main branch. In this case, we merged this version:

$ ajc -version
AspectJ Compiler 1.9.22 - Built: Saturday Mar 23, 2024 at 09:58:15 PDT - Eclipse Compiler b2705b00e91be7 (20Mar2024) - Java22

That corresponds to https://github.com/eclipse-jdt/eclipse.jdt.core/commits/b2705b00e91be7 from Mar-20.

I.e., in the meantime classes like org.eclipse.jdt.internal.compiler.lookup.TypeBinding might have changed in an incompatible way, which here seems to be the case, e.g. there are now two anonymous inner classes $1 and $2 instead of just one in previous versions. Because the relocated classes contained in AspectJ, e.g. org.aspectj.org.eclipse.jdt.internal.compiler.lookup.TypeBinding, ought to match the ones in the original JDT core contained in Eclipse IDE, such changes can cause problems.

One possible workaround would be to recommend to users to upgrade their Eclipse installations (or the versions used for building RCP applications or similar) to an Eclipse integration build a close as possible to the merge point, similarly to the recommendations for 2023-12 in https://github.com/eclipse-aspectj/aspectj/blob/master/docs/developer/IDE.md (see the screenshot after the sentence "Your AspectJ-related list of Eclipse update sites could look like this for Eclipse 2023-12").

How to determine the corresponding I-build for the latest JDT Core merge

  1. Go to the upstream JDT Core commit corresponding to the latest merge into AspectJ JDT Core.

  2. Find the earliest I-build tag for that commit, for which there is a p2 repository:

    image

    image

In this case, the "0620" build does not have any repositories, but the "0740" one does. Therefore, https://download.eclipse.org/eclipse/updates/4.32-I-builds/I20240320-0740/ should be the correct update site for Eclipse.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

@urferr, @k-mierzej If you add https://download.eclipse.org/eclipse/updates/4.32-I-builds/I20240320-0740/ as an update site to your Eclipse IDE or Tyhco build, respectively, does it fix the problem? In Eclipse, you should run IDE updates from that update site and restart the IDE first.

An alternative would be to install Java 22 support from the Eclipse marketplace: https://marketplace.eclipse.org/content/java-22-support-eclipse-2024-03-431. That might also help and would, according to the marketplace entry description, correspond to update site https://download.eclipse.org/eclipse/updates/4.31-P-builds/.

@k-mierzej
Copy link

k-mierzej commented Apr 3, 2024

@kriegaex, I've used the update site, but that didn't change anything. You've focused on compatibility of versions, but is that even possible, given the fact that the same configuration does work on Linux distro? We have like 20+ jdt and compiler modifications and no problems on linux.

I don't think I am able to provide smaller example, those projects which I've uploaded can be imported to Eclipse IDE but some additional plugins would be needed to run them correctly.

Maybe the reporter will add some additional feedback.

EDIT. I've managed to set up eclipse IDE on my windows and launched the example project which I've attached to this ticket and it did not produce the same error... So in my case its only about the distro built using tycho and only windows version of it.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

@k-mierzej, please describe as well as you can how and where you use LTW. Like I said, I see CTW in your build config. Are you using aspectjweaver.jar anywhere or some kind of Eclipse weaving support via OSGi? I know that something like that exists, but have no idea how it works and who maintains it. Maybe it needs to be adjusted to recent changes (since 1.21.1, if I remember correctly) in the weaver, where in case of non-woven code null is returned instead of the original bytes. Tools accessing the weaver API directly need to adjust their code to that new situation. It is an optimisation which helps to avoid problems in other weaving cases, but which also is a breaking change. Fixing the client code should not be a big deal, but it needs to be done. E.g., I am aware of the fact that the IntelliJ IDEA AspectJ plugin needs to be fixed to accomodate the change. Maybe in case of Eclipse weaving support, the situation is similar. But without being able to reproduce it outside of your huge application, I am afraid I cannot help much. Please tell me everything that might clue me in on the root cause.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 3, 2024

@k-mierzej, I have just remembered the name of the other weaving thingy: Equinox Weaving. Maybe whoever maintains that, needs to adjust it to the latest AspectJ changes, if they use weaver classes that otherwise are mostly used by the AspectJ Weaver itself.

@k-mierzej
Copy link

k-mierzej commented Apr 3, 2024

I've created the ticket in equinox GitHub eclipse-equinox/equinox#584

@kriegaex I'm afraid I don't know the answers to your questions because I initially thought that the aspect included in the example project was LTW. I didn't create these aspects in our project; I'm simply trying to update our product to the latest Eclipse version. My knowledge about AspectJ is very limited.

EDIT. As far as I understand, the Eclipse plugin example-aspectplugin-core contains a TestAspect.aj aspect file, which is LTW.

@urferr
Copy link
Author

urferr commented Apr 3, 2024

I have now created a simple Aspectj plugin which, when added to a dropins folder of an Eclipse 2024-03 installation will prevent the Eclipse IDE from being started. A zip file containing the plugin is attached. Here the minimal steps to reproduce the problem

  1. Install Eclipse 2024-03 (i used eclipse-SDK-4.31-win32-x86_64.zip)
  2. Start Eclipse IDE and install "Aspectj Development Tools"
  3. unzip the attached file into the dropins folder under the eclipse folder (eclipse->dropins->plugins->test.loadtimeweaving_1.0.0.202404031741.jar)
  4. Restart the eclipse IDE
  5. Verify that the test plugin is there and activate it. For this open the console view and choose the "Host OSGi Console". Type "ss test" and at least the bundle "test.loadtimeweaving_1.0.0.202404031741" should be displayed with a bundle-id.
  6. Try to create a Java or Aspectj Project -> it fails and in the log file mentioned you can then see the error "java.lang.ClassNotFoundException: org.eclipse.core.internal.resources.ProjectDescription$AjcClosure1 cannot be found by org.eclipse.core.resources_3.20.100.v20240209-1706"

test.loadtimeweaving.zip

@kriegaex
Copy link
Contributor

kriegaex commented Apr 4, 2024

I have now created a simple Aspectj plugin which, when added to a dropins folder of an Eclipse 2024-03 installation will prevent the Eclipse IDE from being started.

Thank you, @urferr. I see that the plugin also contains source files which look strikingly similar to the ones in the aspect module of @k-mierzej's GitHub project. Does your plugin - I have not tried it yet - also work on Linux and fail on Windows like the other one? Please also provide a GitHub source for this minimal plugin. Thank you.

BTW, I just tried running @k-mierzej's GitHub project on Windows Subsystem for Linux and can reproduce the behaviour that it is working there. It proves that weaving as such is working. The different behaviour on Windows and Linux might be caused by a class-loading issue. I have no idea how to debug this. But maybe - and this is pure speculation - the same classes are provided by several plugins or classloaders, and for some reason maybe one of them is woven, but then another unwoven one used. I wish I had an idea how to debug that. Maybe you two can help there. You seem to have way more Eclipse expertise than I do.

I really appreciate your collaborative spirit, both of you.

Another question: Do you know each other or work together? Your use cases look so similar.

@kriegaex kriegaex changed the title loadtime weaving seems not to work in eclipse 2024-03 LTW via OSGi in Eclipse 2024-03 plugins is not working Apr 4, 2024
@k-mierzej
Copy link

@kriegaex We do not know each other. I found this issue randomly, and since the original reporter did not provide an example, I decided to speed up the issue resolution by adding mine. I suppose this is a common use case of AspectJ in Eclipse plugin development, which is why they are somewhat similar.

As for debugging it in Eclipse IDE, I believe it may be extremely challenging because when I ran the plugin directly from my IDE instead of the Tycho-built product, it worked fine.

If you want to run my example from another Eclipse IDE, you'll need to import those projects, but first, you'll need to install three additional Eclipse plugins. I think I could prepare the instructions, but it's somewhat pointless if the issue is not reproducible then.

@kriegaex kriegaex transferred this issue from eclipse-aspectj/aspectj Apr 4, 2024
@kriegaex kriegaex added bug Something isn't working and removed question Further information is requested labels Apr 4, 2024
@kriegaex
Copy link
Contributor

kriegaex commented Apr 4, 2024

When transferring the issue from AspectJ to AJDT, at least one of my comments vanished. So, I am writing it again in a similar way.

I had a suspicion that OSGiWeavingAdaptor::defineClass might be the root cause of the problem, because it tries to use ClassLoader::defineClass via reflection, which on more recent JREs is no longer possible without --add-opens, a phenomenon that was haunting LTW via -javaagent since 1.9.7 already and was just resolved lately, see AspectJ 1.9.21.1 release notes.

After enabling a trace, I can see this on the console when starting @k-mierzej's project on Windows:

$ example-ide/target/products/com.example.ide.product/win32/win32/x86_64/eclipse.exe
SLF4J(W): No SLF4J providers were found.
SLF4J(W): Defaulting to no-operation (NOP) logger implementation
SLF4J(W): See https://www.slf4j.org/codes.html#noProviders for further details.
Apr. 04, 2024 11:14:43 AM org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor defineClass
FEINER: ENTRY o.e.e.w.a.l.OSGiWeavingAdaptor@63d9e1a
Apr. 04, 2024 11:14:43 AM org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor defineClass
FEINER: ENTRY o.e.o.i.l.EquinoxClassLoader@b5311cb org.eclipse.jdt.internal.compiler.lookup.TypeBinding$AjcClosure1 byte[1087]
[org.eclipse.jdt.core.compiler.batch] warning define generated class failed -- (InaccessibleObjectException) Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @377cbdae
Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @377cbdae
java.lang.reflect.InaccessibleObjectException: Unable to make protected final java.lang.Class java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int) throws java.lang.ClassFormatError accessible: module java.base does not "opens java.lang" to unnamed module @377cbdae
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:354)
        at java.base/java.lang.reflect.AccessibleObject.checkCanSetAccessible(AccessibleObject.java:297)
        at java.base/java.lang.reflect.Method.checkCanSetAccessible(Method.java:199)
        at java.base/java.lang.reflect.Method.setAccessible(Method.java:193)
        at org.eclipse.equinox.weaving.aspectj.loadtime.OSGiWeavingAdaptor.defineClass(OSGiWeavingAdaptor.java:169)
        at org.eclipse.equinox.weaving.aspectj.loadtime.OSGiWeavingAdaptor$OSGiGeneratedClassHandler.defineGeneratedClasses(OSGiWeavingAdaptor.java:109)
        at org.eclipse.equinox.weaving.aspectj.loadtime.OSGiWeavingAdaptor.weaveClass(OSGiWeavingAdaptor.java:282)
        at org.eclipse.equinox.weaving.aspectj.AspectJWeavingService.preProcess(AspectJWeavingService.java:154)
        at org.eclipse.equinox.weaving.adaptors.WeavingAdaptor.weaveClass(WeavingAdaptor.java:231)
        at org.eclipse.equinox.weaving.hooks.WeavingHook.processClass(WeavingHook.java:154)
        (...)
        at java.base/java.lang.reflect.Method.invoke(Method.java:568)
        at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:681)
        at org.eclipse.equinox.launcher.Main.basicRun(Main.java:618)
        at org.eclipse.equinox.launcher.Main.run(Main.java:1494)

Apr. 04, 2024 11:14:43 AM org.aspectj.weaver.loadtime.ClassLoaderWeavingAdaptor defineClass
FEINER: RETURN null

This happens, because AJDT still uses a copy of the old AspectJ weaver code. I think, this can be solved by delegating to the super class, but the two existing ClassLoaderWeavingAdaptor::defineClass methods are private in 1.9.22. The plan for now is:

  1. Call ClassLoaderWeavingAdaptor::defineClass reflectively from AJDT for now.
  2. Make the methods protected in the next AspectJ release and adjust AJDT to call the code via super.

kriegaex added a commit that referenced this issue Apr 4, 2024
Call ClassLoaderWeavingAdaptor::defineClass.

TODO: For 2024-06 (4.32), make ClassLoaderWeavingAdaptor::defineClass
protected and call it via super instead of duplicating class definition
code or hackily calling a private method via reflection.

Fixes #57.
@kriegaex
Copy link
Contributor

kriegaex commented Apr 4, 2024

  1. Call ClassLoaderWeavingAdaptor::defineClass reflectively from AJDT for now.

I committed the workaround and published a new AJDT version on the 4.31 update site. @urferr, @k-mierzej, please re-test and report back. For me, it works with @k-mierzej's RCP product, I already tested locally.

BTW, you do not need the I-build Eclipse update site either. Strictly speaking, it would be necessary for another small fix I made locally due to a small breaking change in Eclipse since 2024-03, but this is out of scope here.

kriegaex added a commit to eclipse-aspectj/aspectj that referenced this issue Apr 4, 2024
Relates to eclipse-aspectj/ajdt#57 and it a
precondition for refactoring phase 2 of child class
OSGiWeavingAdaptor::defineClass, which can now directly call the super
methods instead of using reflection.

Signed-off-by: Alexander Kriegisch <[email protected]>
@k-mierzej
Copy link

In my case, it looks like the issue is resolved, thank you @kriegaex

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

@urferr, is there any chance that your plugin wants to weave classes too early in the process of starting the IDE, before AJDT and Equinox AspectJ weaving support are ready? Does maybe your plugin need any extra settings for stuff it depends on, so Eclipse OSGi wires it correctly?

Can you please tell me how I can set log levels to see more? I am really an Eclipse noob, I would appreciate your advice. I double-checked, the IDE definitely contains the latest AJDT build with the updated OSGiWeavingAdaptor class, which solves the problem for @k-mierzej.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

For the record: The IDE does not even start, and there is a whole bunch of exceptions. The last one before failing to start looks like this:

!ENTRY org.eclipse.osgi 4 0 2024-04-05 09:40:39.981
!MESSAGE Application error
!STACK 1
java.lang.NoClassDefFoundError: org/eclipse/core/resources/IContainer
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:153)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:208)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:143)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:109)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:439)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:271)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:568)
	at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:651)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:588)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1459)
Caused by: java.lang.ClassNotFoundException: An error occurred while automatically activating bundle org.eclipse.core.resources (2981).
	at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:134)
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:620)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:348)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:414)
	at org.eclipse.osgi.internal.loader.sources.SingleSourcePackage.loadClass(SingleSourcePackage.java:41)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:516)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:434)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:174)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 13 more
Caused by: org.osgi.framework.BundleException: Exception in org.eclipse.core.resources.ResourcesPlugin.start() of bundle org.eclipse.core.resources.
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:854)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.start(BundleContextImpl.java:775)
	at org.eclipse.osgi.internal.framework.EquinoxBundle.startWorker0(EquinoxBundle.java:1057)
	at org.eclipse.osgi.internal.framework.EquinoxBundle$EquinoxModule.startWorker(EquinoxBundle.java:387)
	at org.eclipse.osgi.container.Module.doStart(Module.java:639)
	at org.eclipse.osgi.container.Module.start(Module.java:498)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:528)
	at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:122)
	... 21 more
Caused by: java.lang.NoClassDefFoundError: org/eclipse/core/internal/resources/ProjectDescription$AjcClosure1
	at org.eclipse.core.internal.localstore.FileSystemResourceManager.read(FileSystemResourceManager.java:917)
	at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:953)
	at org.eclipse.core.internal.resources.SaveManager.restoreMetaInfo(SaveManager.java:933)
	at org.eclipse.core.internal.resources.SaveManager.restore(SaveManager.java:789)
	at org.eclipse.core.internal.resources.SaveManager.startup(SaveManager.java:1615)
	at org.eclipse.core.internal.resources.Workspace.startup(Workspace.java:2615)
	at org.eclipse.core.internal.resources.Workspace.open(Workspace.java:2319)
	at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:571)
	at org.eclipse.core.resources.ResourcesPlugin$WorkspaceInitCustomizer.addingService(ResourcesPlugin.java:1)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:947)
	at org.osgi.util.tracker.ServiceTracker$Tracked.customizerAdding(ServiceTracker.java:1)
	at org.osgi.util.tracker.AbstractTracked.trackAdding(AbstractTracked.java:257)
	at org.osgi.util.tracker.AbstractTracked.trackInitial(AbstractTracked.java:184)
	at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:324)
	at org.osgi.util.tracker.ServiceTracker.open(ServiceTracker.java:267)
	at org.eclipse.core.resources.ResourcesPlugin.start(ResourcesPlugin.java:545)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:833)
	at org.eclipse.osgi.internal.framework.BundleContextImpl$2.run(BundleContextImpl.java:1)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:569)
	at org.eclipse.osgi.internal.framework.BundleContextImpl.startActivator(BundleContextImpl.java:825)
	... 28 more
Caused by: java.lang.ClassNotFoundException: org.eclipse.core.internal.resources.ProjectDescription$AjcClosure1 cannot be found by org.eclipse.core.resources_3.20.100.v20240209-1706
	at org.eclipse.osgi.internal.loader.BundleLoader.generateException(BundleLoader.java:562)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass0(BundleLoader.java:557)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:434)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:174)
	at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:520)
	... 48 more

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

Another note to myself: Could this be about Bundle-ActivationPolicy: lazy, which is used extensively in AJDT? Me being the OSGi noob that I am, I have no idea. But maybe, in some situations this keeps weaving from working when the target classes are Eclipse core classes that need to be initialised very early during IDE initialisation.

The open question is why Eclipse is trying to find class org.eclipse.core.internal.resources.ProjectDescription$AjcClosure1 but failing to do so. Clearly, the class must have been exposed to the weaver before, otherwise its existence would not be known at all.

@urferr
Copy link
Author

urferr commented Apr 5, 2024

The test plugin is completely easy, it just add an around advice to the method org.eclipse.core.internal.resources.ProjectDescription.setNatureIds(String[]) and proceeds the call.

Unfortunately i also don't know how to enable more logging in eclipse which could help to analyze the problem.

I also have now upgraded several of my development environment to eclipse 2024-03 with the latest AJDT plugin version and all are working fine. I did not have any errors so far. But everywhere i first deleted the existing eclipse installation and created a new one instead of just upgrading the existing one.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

I am happy it is working for you. For me, it is not, maybe due to other installed plugins or other config peculiarities. That means, it could fail again for others, which leaves me with an uneasy feeling. I would not require users to always install Eclipse from scratch only to upgrade AJDT.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

I installed AJDT and the test plugin in a fresh 2024-03 workspace. At first, it worked, but after creating an AspectJ project, playing around with it and restarting the IDE, it started failing again. @urferr, maybe your solution IDE also starts failing after a while. Please, let me know.

After deleting the workspace and starting over, I could start the AspectJ project creation wizard, but when I changed some settings in the wizard (JRE execution environment changed to 1.8 with JDK 22), the error occurred while the wizard was still open. I.e., the AJDT bugfix does not seem to work everywhere for reasons I do not understand. All I know is that there are no AspectJ or AJDT classes in the stacktrace, other than the generated ProjectDescription$AjcClosure1 class that cannot be found.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

After deleting the workspace and restarting Eclipse, I see this:

image

The error goes away, if I remove the drop-in plugin.

@urferr
Copy link
Author

urferr commented Apr 5, 2024

Strange. but it seems that is has something to do with data cached under eclipse/configuration. I tried now again with the test system i was successful this morning and this was now suddenly not working anymore even i did not touch it since this morning.

Then i have deleted the .metadata folder in the workspace and started eclipse again. Starting was successful but i could not import the project anymore. When i tried it always failed with missing ProjectDescription.$AjcClosure1.

Next i have deleted everything und eclipse/configuration except the folder org.eclipse.equinox.simpleconfigurator and the file config.ini. Starting eclipse was successful and now i could also import the projects again and the loadtime weaving works fine. Unfortunately i am not familiar with the content of eclipse/configuration except the folder and the file i did not delete but i assume it has something to do with the org.eclipse.osgi folder and its content.

Now i have create a Java class and an Aspect stop the eclipse ide and wanted to start is again and have the problem. After deleting the eclipse/configuration/org.eclipse.osgi folder i could start the eclipse ide again. So the problem seems really be in some data store under the eclipse/configuration/org.eclipse.osgi. Most probably the equinox guys know what is stored under this folder.
My development environment may work for quite some time if my expectations are correct because the aspects are very stable and haven't been changed since years

@urferr
Copy link
Author

urferr commented Apr 5, 2024

My expectation was not completely correct. As soon as i create a new java class in any project i cannot start the eclipse ide anymore after closing it. I always have to delete the folder eclipse/configuration/org.eclipse.osgi to make it working again.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 5, 2024

Thanks for these details. That sounds similar to my experience. Maybe we should reopen the other issue over there again.

@urferr
Copy link
Author

urferr commented Apr 5, 2024

I just found a workaround but then starting eclipse ide is much slower. If you add -Dosgi.clean=true to the eclipse.ini in the part of the vm arguments then it seems that this cache is always recreated even a log file is created under eclipse/configuation with the following content:

!SESSION 2024-04-05 16:48:46.444 -----------------------------------------------
eclipse.buildId=4.31.0.I20240229-0520
java.version=17.0.8
java.vendor=Eclipse Adoptium
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=de_CH

!ENTRY org.eclipse.osgi 4 0 2024-04-05 16:48:47.001
!MESSAGE The -clean (osgi.clean) option was not successful. Unable to clean the storage area: D:\JavaProjects\xentis\600\eclipse\configuration\org.eclipse.osgi

@martinlippert
Copy link

@kriegaex I haven't tried the example myself, but while reading through this the caching service comes to my mind. The basic idea is: if you weave aspects on every startup of the IDE, it is really slowing things down significantly and causing quite some additional memory to be consumed. Therefore, the idea is to cache the woven classes and let the weaving service use those cached woven class bytecodes when a class is loaded. This should - of course - be kept around until something changes (like new aspects being installed, plugins being upgraded, etc.).

If you want to debug into this, the fundamental caching logic is implemented in

https://github.com/eclipse-equinox/equinox/tree/master/bundles/org.eclipse.equinox.weaving.hook.

The concrete storage of the cached bytecode in files is implemented in

https://github.com/eclipse-equinox/equinox/tree/master/bundles/org.eclipse.equinox.weaving.caching

Why is this in different bundles and abstracted via an ICachingService? The reason is that we had a J9 JVM specific caching implemented back then as well, which used J9-specific API to cache bytecode. Otherwise, the caching wouldn't have worked when running on J9 (back then).

I have no concrete idea in mind what exactly might be going wrong here, but your problem descriptions sound like something in the caching area. But that implementation hasn't really changed since years, so I wonder why the basic caching should suddenly break - since it is completely independent of the way the AspectJ weaving is done.

The caching itself is independent of the concrete weaving logic, whether it is AspectJ doing weaving or something else, so I wonder how those changes in the AspectJ weaving service implementation could affect this, but those are more questions than answers... :-)

@kriegaex
Copy link
Contributor

kriegaex commented Apr 6, 2024

If you want to debug into this

@martinlippert, I think I am in way over my head here already. I need help. Can you please help me? I am offering to directly collaborate with you in a debugging session with desktop sharing. I can contribute some AspectJ and AJDT and you some Equinox weaving/caching knowledge. Otherwise, this is going to take too much time, and I will probably not look into it, because I see little chance to sort this out by myself.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 7, 2024

@xpomul, you lately contributed some caching fixes both to AJDT and Equinox. Can you maybe take a look what is happening here, please? Your contributed OSGiWeavingAdaptorTest is also failing now, and I am not sure why. It says something like:

junit.framework.AssertionFailedError: my.foo.MyClass$AjcClosure1 is not contained in [my.foo.MyBaseClass]

	at junit.framework.Assert.fail(Assert.java:57)
	at junit.framework.Assert.assertTrue(Assert.java:22)
	at junit.framework.TestCase.assertTrue(TestCase.java:192)
	at org.eclipse.equinox.weaving.aspectj.tests.OSGiWeavingAdaptorTest.testGeneratedClasses(OSGiWeavingAdaptorTest.java:103)
	at (...)

@kriegaex
Copy link
Contributor

kriegaex commented Apr 7, 2024

Update: I deployed an AspectJ 1.9.23 snapshot with some small changes. They do not fix the problem, but help in debugging and running tests. If you check out branch e431, the build will use that version.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 8, 2024

@xpomul, reverting eclipse-aspectj/aspectj#278 fixes your test, but not the problem in real life. eclipse-aspectj/aspectj@8a4aa03 seems to influence the result. Can you advise me how to adjust AJDT to that change?

@xpomul
Copy link
Contributor

xpomul commented Apr 8, 2024

@kriegaex I will try to find some time tomorrow to check out the issue.

kriegaex added a commit to eclipse-aspectj/aspectj that referenced this issue Apr 8, 2024
This was introduced in commit 8a4aa03 of PR #278 contribution as part
of the #279 fix. The contributor thought that the generated closure
class entries were never used, but in fact AJDT class OSGiWeavingAdaptor
relies on the presence of those entries.

To the best of my present knowledge, it looks as if this change was the
root cause of eclipse-aspectj/ajdt#57.
Therefore, I reverted it, simultaneously refactoring Iterator::remove
usage to delete entries from the map to Collection::removeIf.

Signed-off-by: Alexander Kriegisch <[email protected]>
kriegaex added a commit to eclipse-aspectj/aspectj that referenced this issue Apr 8, 2024
This was introduced in commit 8a4aa03 of PR #278 contribution as part
of the #279 fix. The contributor thought that the generated closure
class entries were never used, but in fact AJDT class OSGiWeavingAdaptor
relies on the presence of those entries.

To the best of my present knowledge, it looks as if this change was the
root cause of eclipse-aspectj/ajdt#57.
Therefore, I reverted it, simultaneously refactoring Iterator::remove
usage to delete entries from the map to Collection::removeIf.

Signed-off-by: Alexander Kriegisch <[email protected]>
@kriegaex
Copy link
Contributor

kriegaex commented Apr 8, 2024

@urferr, @k-mierzej: I might have found the root cause. It seems to be a premature optimisation in a recently contributed PR to AspectJ, which I have reverted. Please try with the AJDT version I have just published on the 4.31 update site. The version number should be 2.2.4.202404081252 or newer.

@martinlippert, I hope I will not need your help anymore.

@xpomul, I would be glad if you would review this. As you can see, I also changed something in OSGiWeavingAdaptorTest in commit 84c7931 as a consequence of the changes in AspectJ. Please re-test if on top of the passing test your weaving scenario in real life also still works as expected.

@kriegaex
Copy link
Contributor

kriegaex commented Apr 8, 2024

I am closing this issue, because I think it is fixed. In case of negative re-testing feedback we can reopen it again. For the record, we had two separate problems here:

@kriegaex kriegaex closed this as completed Apr 8, 2024
@urferr
Copy link
Author

urferr commented Apr 8, 2024

Have retested all my eclipse ide installations and it looks fine. Thanks @kriegaex

@martinlippert
Copy link

That is great news @kriegaex and @urferr, awesome to hear that you solved this issue. And sorry that I couldn't spend more time on this myself. I hope my feedback/input helped you along the way.

@xpomul
Copy link
Contributor

xpomul commented Apr 9, 2024

@xpomul, I would be glad if you would review this. As you can see, I also changed something in OSGiWeavingAdaptorTest in commit 84c7931 as a consequence of the changes in AspectJ. Please re-test if on top of the passing test your weaving scenario in real life also still works as expected.

Directly added a comment to the commit: 84c7931#commitcomment-140770901

kriegaex added a commit that referenced this issue Apr 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

5 participants