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.

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
1 participant