openhab/openhab-distro

Add support for running openHAB with Java 21

wborn opened this issue ยท 14 comments

wborn commented

Today Java 21 will be launched. ๐Ÿš€ This is a LTS release, so we should also support using it with openHAB.

We can use this issue to keep track of what still needs to be fixed or investigated (similar to #1316).

There's also a launch live stream: https://dev.java/community/java-21-launch/

TODO:

wborn commented

It seems that official Java 21 releases are delayed (see Temurin blog).

Nevertheless I was able to use the Temurin 21-beta+34-202308082331 nightly build and got OH 4.1.0-SNAPSHOT running without issues so far after disabling the recently added Java compatibility check.

It seems the recent Karaf 4.4.4 upgrade helped a lot because OH 4.0.3 does not start with Java 21:

2023-10-02 11:59:11.900 [SEVERE] [org.apache.karaf.main.Main] - Could not launch framework
java.lang.IllegalStateException: Error initializing storage for Equinox container.
	at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:110)
	at org.eclipse.osgi.launch.Equinox.<init>(Equinox.java:53)
	at org.eclipse.osgi.launch.EquinoxFactory.newFramework(EquinoxFactory.java:35)
	at org.eclipse.osgi.launch.EquinoxFactory.newFramework(EquinoxFactory.java:30)
	at org.apache.karaf.main.Main.launch(Main.java:291)
	at org.apache.karaf.main.Main.main(Main.java:183)
Caused by: java.lang.RuntimeException: Error occurred while checking the system module.
	at org.eclipse.osgi.storage.Storage.checkSystemBundle(Storage.java:467)
	at org.eclipse.osgi.storage.Storage.createStorage(Storage.java:187)
	at org.eclipse.osgi.internal.framework.EquinoxContainer.<init>(EquinoxContainer.java:108)
	... 5 more
Caused by: org.osgi.framework.BundleException: Invalid manifest header Export-Package: "org.osgi.dto;version="1.1",org.osgi.resource;version="1.0",org.osgi.resource.dto;version="1.0";uses:="org.osgi.dto",org.osgi.framework;version="1.10",org.osgi.framework.dto;version="1.10";uses:="org.osgi.dto",org.osgi.framework.hooks.bundle;version="1.1";uses:="org.osgi.framework",org.osgi.framework.hooks.resolver;version="1.0";uses:="org.osgi.framework.wiring",org.osgi.framework.hooks.service;version="1.1";uses:="org.osgi.framework",org.osgi.framework.hooks.weaving;version="1.1";uses:="org.osgi.framework.wiring",org.osgi.framework.launch;version="1.2";uses:="org.osgi.framework",org.osgi.framework.namespace;version="1.1";uses:="org.osgi.resource",org.osgi.framework.startlevel;version="1.0";uses:="org.osgi.framework",org.osgi.framework.startlevel.dto;version="1.0";uses:="org.osgi.dto",org.osgi.framework.wiring;version="1.2";uses:="org.osgi.framework,org.osgi.resource",org.osgi.framework.wiring.dto;version="1.3";uses:="org.osgi.dto,org.osgi.resource.dto",org.osgi.service.condpermadmin;version="1.1.1";uses:="org.osgi.framework,org.osgi.service.permissionadmin",org.osgi.service.packageadmin;version="1.2";uses:="org.osgi.framework",org.osgi.service.permissionadmin;version="1.2",org.osgi.service.resolver;version="1.1";uses:="org.osgi.resource",org.osgi.service.startlevel;version="1.1";uses:="org.osgi.framework",org.osgi.service.url;version="1.0",org.osgi.util.tracker;version="1.5.2";uses:="org.osgi.framework",org.apache.karaf.version;version="4.4.3",org.apache.karaf.jaas.boot.principal;uses:=javax.security.auth;version="4.4.3",org.apache.karaf.jaas.boot;uses:="javax.security.auth,javax.security.auth.callback,javax.security.auth.login,javax.security.auth.spi,org.osgi.framework";version="4.4.3",org.apache.karaf.info;version="4.4.3",, org.apache.karaf.branding, sun.misc, com.sun.jmx.remote.protocol, com.sun.jmx.remote.protocol.jmxmp, org.apache.karaf.jaas.boot.principal;uses:=javax.security.auth;version=4.4.3, org.apache.karaf.jaas.boot;uses:="javax.security.auth,javax.security.auth.callback,javax.security.auth.login,javax.security.auth.spi,org.osgi.framework";version=4.4.3, org.apache.karaf.diagnostic.core;uses:=org.osgi.framework;version=4.4.3, org.apache.karaf.diagnostic.core.common;uses:=org.apache.karaf.diagnostic.core;version=4.4.3"
	at org.eclipse.osgi.util.ManifestElement.parseHeader(ManifestElement.java:355)
	at org.eclipse.osgi.container.builders.OSGiManifestBuilderFactory.createBuilder(OSGiManifestBuilderFactory.java:109)
	at org.eclipse.osgi.storage.Storage.getBuilder(Storage.java:835)
	at org.eclipse.osgi.storage.Storage.checkSystemBundle(Storage.java:415)
	... 7 more

We might also want to upgrade Netty to 4.1.99.Final or newer because it can crash the JVM, see:

https://netty.io/news/2023/09/21/4-1-99-Final.html

This issue has been mentioned on openHAB Community. There might be relevant details there:

https://community.openhab.org/t/openhab-4-1-release-discussion/152252/44