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

feat(osgi): add org.osgi.framework.executionenvironment #5634

Draft
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

gnunzi
Copy link
Contributor

@gnunzi gnunzi commented Jan 7, 2025

This PR adds org.osgi.framework.executionenvironment=JavaSE-9 to the config.ini, so that Equinox ClassLoaders do not load JRE-classes again. This avoids LinkageError for javax.* classes.

Equinox reads the lists "jvm packages" from the property org.osgi.framework.bootdelegation and "delegates" these packages to the jvm class loader.

Without "bootdelegation" an Equinox ClassLoader loads the javax.* classes and a LinkageError occurs. See related issues below.

Related Issue:
This PR fixes #5630 and #4141.

Description of the solution adopted:
The javax.* classes must not be loaded by Equinox, since they are provided by the jre and loaded by the jvm itself (boot classloader / platform classloader).

The solution is to specify org.osgi.framework.executionenvironment. This is based on the following thread:

So as long as you define a "org.osgi.framework.executionenvironment", equinox should load the right JVM packages and export them for consumption by the bundles.

From my understanding the setting org.osgi.framework.executionenvironment tells Equinox to load the JSE-9 profile which in turn contains the properties org.osgi.framework.system.packages and org.osgi.framework.bootdelegation (see here and here)

The mechanism of Class Loading is explained in https://docs.osgi.org/specification/osgi.core/8.0.0/framework.module.html#framework.module.parentdelegation.

org.osgi.framework.executionenvironment is explained here: https://docs.osgi.org/specification/osgi.core/7.0.0/framework.lifecycle.html

Nore that org.osgi.framework.executionenvironment is deprecated in older OSGi releases, but valid in R4 like Equinox.

Screenshots:

N/A

Manual Tests

Any side note on the changes made:

StackTrace in Java 1.8:
Caused by: java.util.concurrent.ExecutionException: java.lang.LinkageError: loader constraint violation in interface itable initialization: when resolving method "org.h2.jdbcx.JdbcXAConnection.getXAResource()Ljavax/transaction/xa/XAResource;" the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) of the current class, org/h2/jdbcx/JdbcXAConnection, and the class loader (instance of <bootloader>) for interface javax/sql/XAConnection have different Class objects for the type javax/transaction/xa/XAResource used in the signature

Especially look at the following: the class loader (instance of org/eclipse/osgi/internal/loader/EquinoxClassLoader) of the current class, org/h2/jdbcx/JdbcXAConnection, and the class loader (instance of <bootloader>) [...] have different Class objects for the type javax/transaction/xa/XAResource used in the signature.

Copy link
Contributor

github-actions bot commented Mar 9, 2025

This pull request is stale because it has been open for 60 days with no activity.

@github-actions github-actions bot added the Stale label Mar 9, 2025
@MMaiero
Copy link
Contributor

MMaiero commented Mar 12, 2025

@gnunzi This PR has been flag by the automation as stale. Are you still willing to contribute this change? Or can this be closed?

@github-actions github-actions bot removed the Stale label Mar 13, 2025
@gnunzi
Copy link
Contributor Author

gnunzi commented Mar 26, 2025

@MMaiero In principle yes. I believe this PR is the solution to java.lang.LinkageError that has been reported a couple of times.
To my understanding the LinkageError occurs when a bundle is loaded after the start, e.g. hot-deployment in a Docker container (my observation) or plugin-deployment throught the UI (reported in #5630 and #4141).

On the other side, it is difficult for me to reproduce this error and check the result. I would keep this PR with the hope to reproduce the error.

In any case we are using org.osgi.framework.executionenvironment=JavaSE-9 with no side-effect already. I could submit the PR right away if the text on top is convincing enough. For a reproducable error I need more time.

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 this pull request may close these issues.

Conflict while loading javax.transaction.xa.XAResource on JDK 17
2 participants