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

Bundle with Export-Package javax.annotation prevents Eclipse from starting #727

Closed
guw opened this issue Apr 22, 2023 · 17 comments · Fixed by eclipse-orbit/orbit#11
Closed

Comments

@guw
Copy link
Contributor

guw commented Apr 22, 2023

Noticed an interesting exception when trying to run an Eclipse Application self-hosted.

!ENTRY org.eclipse.osgi 4 0 2023-04-22 11:23:57.490
!MESSAGE Application error
!STACK 1
java.lang.NullPointerException: Cannot invoke "org.eclipse.emf.ecore.resource.Resource.getContents()" because "applicationResource" is null
	at org.eclipse.e4.ui.internal.workbench.ResourceHandler.loadMostRecentModel(ResourceHandler.java:182)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.loadApplicationModel(E4Application.java:371)
	at org.eclipse.e4.ui.internal.workbench.swt.E4Application.createE4Workbench(E4Application.java:247)
	at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:572)
	at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:338)
	at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:550)
	at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:171)
	at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:152)
	at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:203)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:136)
	at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:104)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:402)
	at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:255)
	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:659)
	at org.eclipse.equinox.launcher.Main.basicRun(Main.java:596)
	at org.eclipse.equinox.launcher.Main.run(Main.java:1467)
	at org.eclipse.equinox.launcher.Main.main(Main.java:1440)

The issue is caused by having JSR 305 available in the target platform (dsl):

	dependency {
		groupId="com.google.code.findbugs"
		artifactId="jsr305"
		version="3.0.2"
	}

The problem is that org.eclipse.e4.ui.workbench (and a lot other bundles) get wired to the JSR 305 provided package because they use Import-Package and the package is exported with a higher version. However, the problem is that JSR 305 does not provide a PostConstruct annotation. Therefore e4 DI does not invoke the init method on ResourceHandler.

image

org.eclipse.e4.core.di is doing Require-Bundle:
image

This is a difficult split-package situation. I think the JSR bundle should export packages with split attribute. Same probably applies to the javax.annotation bundle but I am afraid this will break lots of existing plug-ins.

Note, I don't have a recommendation for a fix yet. But I wanted to report the issue for visibility. It's easy to run into with Maven support in target platforms.

@guw guw changed the title NullPointerException: Cannot invoke "org.eclipse.emf.ecore.resource.Resource.getContents()" because "applicationResource" is null Bundle with Export-Package javax.annotation prevents Eclipse from starting Apr 23, 2023
@guw
Copy link
Contributor Author

guw commented Apr 23, 2023

I think I found a relative small fix. The questions is, whether the upstream project would be willing to integrated that.

Adding this to the MANIFEST.MF of the com.google.code.findbugs:jsr305 artifact helps:

Require-Bundle: javax.annotation;bundle-version="1.3.5";resolution:=optional;visibility:=reexport

@guw
Copy link
Contributor Author

guw commented May 3, 2023

@iloveeclipse would you be able to publish a new version of that artifact into Maven Central? Should I open a new bug with Spotbugs to re-publish jsr305?

@iloveeclipse
Copy link
Member

would you be able to publish a new version of that artifact into Maven Central?

I personally not, I haven't touched Maven publishing topic in my life.

Should I open a new bug with Spotbugs to re-publish jsr305?

jsr305 is dead and shouldn't be used. Why do you use it?

@guw
Copy link
Contributor Author

guw commented May 3, 2023

jsr305 is dead and shouldn't be used. Why do you use it?

Vendoring third-party source code for the Bazel Eclipse plug-in. It's heavily used within Google OSS code.

@iloveeclipse
Copy link
Member

It's heavily used within Google OSS code

You mean "jsr305" is used there. That's because the original findbugs author introduced that there long time ago but had no interest to continue but we have to live since that with the abandoned JSR...

Well, you could try to open a ticket for spotbugs, and provide a PR which I could merge, but I have no idea who did the publishing (probably @KengoTODA) and how it is done.

@merks
Copy link
Contributor

merks commented May 3, 2023

The Platform does Maven publishing. Also EMF. So I have some idea how it's done. It's not trivially easy though...

@HannesWell
Copy link
Member

@guw I think this problem should already be solved with #738.

Luckily the jsr-305bundle exports its package with a proper version of 3.0.2:

Export-Package: javax.annotation;uses:="javax.annotation.meta";version
 ="3.0.2",javax.annotation.concurrent;version="3.0.2",javax.annotation
 .meta;uses:="javax.annotation";version="3.0.2"

So with the applied version range of [1,2), the importing bundles cannot be wired to jsr305.
And at least the javax.annotation bundle provided by jakarata (to which I'm currently migrating platform, see https://github.com/eclipse-platform/eclipse.platform.releng.aggregator/issues/1056) exports the javax.package in version 1.3.5. Haven't checked javax.annotation from Orbit, but it probably has a similar version for the package export.

@guw
Copy link
Contributor Author

guw commented May 3, 2023

Yes, that should help. Is this available in an integration build for testing?

@HannesWell
Copy link
Member

Yes, that should help. Is this available in an integration build for testing?

It should be available in the two latest I-builds.

@guw
Copy link
Contributor Author

guw commented May 3, 2023

@HannesWell confirmed it does not work. :(

Needs to restrict import version range also in Orbit
eclipse-orbit/orbit#11

@guw
Copy link
Contributor Author

guw commented May 4, 2023

@HannesWell It was marked completed but I re-open because javax.annotation needs to be added in some feature.xml I suspect.

@guw guw reopened this May 4, 2023
@HannesWell
Copy link
Member

@HannesWell It was marked completed but I re-open because javax.annotation needs to be added in some feature.xml I suspect.

It is included in some features, I think what actually needs to be done is to update the version/qualifier change in the eclipse-sdk-prereqs.target.
But I'm currently in the process in migrating the javax.annotation bundle to the one provided by jakarta in eclipse-platform/eclipse.platform.releng.aggregator#1057, which would make the Orbit bundle obsolete anyway.

@guw
Copy link
Contributor Author

guw commented May 5, 2023

But I'm currently in the process in migrating the javax.annotation bundle to the one provided by jakarta in eclipse-platform/eclipse.platform.releng.aggregator#1057, which would make the Orbit bundle obsolete anyway.

@HannesWell Do those provide proper boundaries on the imports? Also, what's your plan for continue supporting plugins written using the old javax.annotations.PostConstruct api? Doesn't the old Orbit javax.annotation package still needs to be around for that?

@HannesWell
Copy link
Member

@HannesWell Do those provide proper boundaries on the imports?

That's the (stripped to the relevant) Manifest of jakarta.annotation-api-1.3.5.jar:

Manifest-Version: 1.0
Bundle-Description: Jakarta Annotations API
Automatic-Module-Name: java.annotation
Bundle-SymbolicName: jakarta.annotation-api
Bundle-ManifestVersion: 2
Specification-Vendor: Eclipse Foundation
Bundle-Vendor: Eclipse Foundation
Require-Capability: osgi.ee;filter:="(&(osgi.ee=JavaSE)(version=1.8))"
Export-Package: javax.annotation.security;version="1.3.5",javax.annota
 tion.sql;version="1.3.5",javax.annotation;version="1.3.5"
Bundle-Name: Jakarta Annotations API
Bundle-Version: 1.3.5
Extension-Name: jakarta.annotation

It does not contain any Import-Package, so I think it's fine :)

Also, what's your plan for continue supporting plugins written using the old javax.annotations.PostConstruct api? Doesn't the old Orbit javax.annotation package still needs to be around for that?

The jakarta.annotation:jakarta.annotation-api:1.3.5 artifact contains the annotation in the 'old' javax.annotation namespace. Only with version 2 the package names are switched to jakarta.annotation. So as long as only Import-Package: javax.annotation is used the jakarta-annotation-1.3.5 jar is a drop-in replacement for the javax.annotation bundle from Orbit. Preparing that is part of eclipse-platform/eclipse.platform.releng.aggregator#1056.

@akurtakov
Copy link
Member

Is this one still relevant?

@laeubi
Copy link
Contributor

laeubi commented Oct 23, 2023

The main problem is here that actually the findbugs annotations *are not meant to be included at runtime, they are compile time (and probably class/tool analysis time), so one actually should never have them anywhere in a running eclipse...

Sadly here again findbugs is a bit odd as some are marked with RUNTIME (for whatever reason...):
https://stackoverflow.com/questions/2284433/findbugs-annotations-do-i-need-annotation-jar-and-jsr305-jar-in-my-deployed-co

Nevertheless excluding them should only result in them not be resolvable, so if you never query them at runtime it should be perfectly safe to simply exclude them from your product at all.

@guw
Copy link
Contributor Author

guw commented Oct 23, 2023

@akurtakov Thanks to the work of @HannesWell this is no longer an issue. I'll close it.

@guw guw closed this as completed Oct 23, 2023
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

Successfully merging a pull request may close this issue.

6 participants