feat(osgi): add org.osgi.framework.executionenvironment #5634
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
From my understanding the setting
org.osgi.framework.executionenvironment
tells Equinox to load the JSE-9 profile which in turn contains the propertiesorg.osgi.framework.system.packages
andorg.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.