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

Add support for running openHAB with Java 17 #1316

Closed
9 tasks done
wborn opened this issue Sep 19, 2021 · 20 comments
Closed
9 tasks done

Add support for running openHAB with Java 17 #1316

wborn opened this issue Sep 19, 2021 · 20 comments
Labels
enhancement An enhancement or new feature

Comments

@wborn
Copy link
Member

wborn commented Sep 19, 2021

Java 17 was released on September 14th. This is a LTS release, so we should also support using it with openHAB.

This issue keeps track of what still needs to be fixed or investigated:

@wborn wborn added the enhancement An enhancement or new feature label Sep 19, 2021
@wborn wborn pinned this issue Sep 19, 2021
@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/openhab-and-future-jdk-versions-when/65572/43

@wborn
Copy link
Member Author

wborn commented Sep 19, 2021

The runtime seems to start with Java 17 🙂, but as expected DSL rules don't work:

[ERROR] [re.automation.internal.RuleEngineImpl] - Failed to execute rule ‘demo-8' with status 'UNINITIALIZED'

It's probably due to this exception:

[DEBUG] [.access.reflect.ReflectionTypeFactory] - class org.eclipse.xtext.common.types.access.reflect.ReflectionTypeFactory cannot access interface jdk.internal.util.random.RandomSupport$RandomGeneratorProperties (in module java.base) because module java.base does not export jdk.internal.util.random to unnamed module @1d03e645
java.lang.IllegalAccessException: class org.eclipse.xtext.common.types.access.reflect.ReflectionTypeFactory cannot access interface jdk.internal.util.random.RandomSupport$RandomGeneratorProperties (in module java.base) because module java.base does not export jdk.internal.util.random to unnamed module @1d03e645
	at jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:392) ~[?:?]
	at java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:674) ~[?:?]
	at java.lang.reflect.Method.invoke(Method.java:560) ~[?:?]
	at org.eclipse.xtext.common.types.access.reflect.ReflectionTypeFactory.createAnnotationReference(ReflectionTypeFactory.java:204) ~[bundleFile:?]
	at org.eclipse.xtext.common.types.access.reflect.ReflectionTypeFactory.createAnnotationValues(ReflectionTypeFactory.java:190) ~[bundleFile:?]
	at org.eclipse.xtext.common.types.access.reflect.ReflectionTypeFactory.createType(ReflectionTypeFactory.java:164) ~[bundleFile:?]
	at org.eclipse.xtext.common.types.access.reflect.ReflectionTypeFactory.createType(ReflectionTypeFactory.java:84) ~[bundleFile:?]
	at org.eclipse.xtext.common.types.access.impl.ClassMirror.initialize(ClassMirror.java:55) ~[bundleFile:?]

As a result "Rule DSL" also doesn't show as an option when adding rules via the UI.

Because Nashorn was removed in Java 15, ECMAScript also doesn't show. It might still be possible to create an Automation add-on using nashorn-core for backwards compatibility and if GraalVM is not available for your architecture, see also: https://github.com/openjdk/nashorn .

@J-N-K
Copy link
Member

J-N-K commented Jan 4, 2022

Regarding XStream: I'm not too confident we'll see a Java 17 implementation anytime soon (in contrast to XText where at least a roadmap exists). Maybe a change to Jakarta XML Binding 3 should be considered. There are already some addons using JAXB 2.x (while some others use XStream), so this could be unified, too.

@Flole998
Copy link
Member

@wborn Seems like Azul has published an armhf version now, so I think you can mark that as completed.

@wborn
Copy link
Member Author

wborn commented Feb 20, 2022

Regarding XStream: I'm not too confident we'll see a Java 17 implementation anytime soon (in contrast to XText where at least a roadmap exists).

I haven't seen any XStream issues so far with my distro builds on Java 17. Only when running unit tests there were some:

com.thoughtworks.xstream.converters.ConversionException: 
No converter available
---- Debugging information ----
message             : No converter available
type                : java.util.Collections$UnmodifiableRandomAccessList
converter           : com.thoughtworks.xstream.converters.reflection.ReflectionConverter
message[1]          : Unable to make field private static final long java.util.Collections$UnmodifiableCollection.serialVersionUID accessible: module java.base does not "opens java.util" to unnamed module @5b6fe39e
-------------------------------
	at org.openhab.core.config.xml.util.XmlDocumentReaderTest.defaultSecurityAllowsDeserializingOHCobjects(XmlDocumentReaderTest.java:70)

It looks like the add-opens workaround most issues. So I've also added them to fix similar issues for the unit tests in openhab/openhab-core#2788.

I also saw similar issues with Gson deserialization in tests. Upgrading to Gson 2.9.0 fixed the issues I ran into (Fix failing to serialize Collection or Map with inaccessible constructor), as well as the add-opens workaround.

@wborn
Copy link
Member Author

wborn commented Feb 20, 2022

There are also some new annoying warnings we might want to look into. 🙄

You'll see this on startup:

WARNING: A terminally deprecated method in java.lang.System has been called
WARNING: System::setSecurityManager has been called by org.eclipse.osgi.internal.framework.SystemBundleActivator (file:runtime/system/org/eclipse/platform/org.eclipse.osgi/3.16.300/org.eclipse.osgi-3.16.300.jar)
WARNING: Please consider reporting this to the maintainers of org.eclipse.osgi.internal.framework.SystemBundleActivator
WARNING: System::setSecurityManager will be removed in a future release

Similar warnings are printed when SAT runs Spotbugs on Java 17. See: spotbugs/spotbugs#1579

@wborn wborn added this to In Progress in openHAB 3.4 Issue Tracking Feb 20, 2022
@J-N-K
Copy link
Member

J-N-K commented Feb 20, 2022

@wborn XStream: That's good to hear. I just read the issue you linked above and it seems to be an issue. Probably we don't have private final fields in objects we serialize/deserialize.

@wborn
Copy link
Member Author

wborn commented Apr 2, 2022

Because Nashorn was removed in Java 15, ECMAScript also doesn't show. It might still be possible to create an Automation add-on using nashorn-core for backwards compatibility and if GraalVM is not available for your architecture, see also: https://github.com/openjdk/nashorn .

I've created a JSScripting (Nashorn) add-on using the standalone Nashorn Engine which can be installed using the Marketplace.

@J-N-K
Copy link
Member

J-N-K commented Apr 3, 2022

That (together with openhab/openhab-core#2883) and the next release of KARAF all issues seem to be resolved.

@wborn
Copy link
Member Author

wborn commented Apr 3, 2022

Yes your transformation PRs look very promising! 👍 I plan on testing them soon. 🙂 Do you know if multiple JS scripting engines are also supported by the script transformation/profile in case users are still migrating between engines?

@J-N-K
Copy link
Member

J-N-K commented Apr 3, 2022

Yes, it should, because they use different mime-types. The nashorn engine uses application/javascript and the Graal engine uses application/javascript;version=ECMAScript-2021, so depending on what is set as script-type, one of these will be selected.

wborn added a commit to wborn/openhab-distro that referenced this issue Apr 27, 2022
* Syncs distro customizations with Karaf 4.3.7
* Resolves app runbundles for the new dependencies

For release notes, see:

https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12311140&version=12351181

This fixes warnings when starting the runtime with Java 17 (openhab#1316).

Signed-off-by: Wouter Born <github@maindrain.net>
wborn added a commit to wborn/openhab-distro that referenced this issue Apr 27, 2022
* Syncs distro customizations with Karaf 4.3.7
* Resolves app runbundles for the new dependencies

For release notes, see:

https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12311140&version=12351181

This fixes warnings when starting the runtime with Java 17 (openhab#1316).

Signed-off-by: Wouter Born <github@maindrain.net>
kaikreuzer pushed a commit that referenced this issue Apr 28, 2022
* Syncs distro customizations with Karaf 4.3.7
* Resolves app runbundles for the new dependencies

For release notes, see:

https://issues.apache.org/jira/secure/ReleaseNote.jspa?projectId=12311140&version=12351181

This fixes warnings when starting the runtime with Java 17 (#1316).

Signed-off-by: Wouter Born <github@maindrain.net>
@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/java-17/135948/2

@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/building-on-linux-vs-windows/136338/2

@J-N-K
Copy link
Member

J-N-K commented Jun 1, 2022

Regarding the Nashorn add-on: I think this should be added because otherwise a lot of code will need changing.

@florian-h05
Copy link
Contributor

Regarding Java 17, do you know if the automatic file reloading of the JS Scripting add-on is working?

I am asking, because yesterday someone opened an issue on openhab-js and had problems with files not loading on Java 17: openhab/openhab-js#130.

@J-N-K
Copy link
Member

J-N-K commented Jun 6, 2022

The reason is that Nashorn is missing on Java 17:

The ScriptFileWatcher checks if an engine is available for the type js before it loads a file. The subclass JSScriptFileWatcher (watching automation/js) overloads the createAndLoad method, so after the super class found out that the script type is supported, it'll use the Graal Engine to process the script.

On Java 11 this works, because Nashorn is available. On Java 17 Nashorn is not available, so the script type js is not registered and the createAndLoad method is never called. I'll provide a fix for that.

@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/send-command-to-serial-port-and-receive-a-answer/138672/64

@wborn wborn removed this from In Progress in openHAB 3.4 Issue Tracking Dec 19, 2022
@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/openhab-4-0-snapshot-discussion/142322/22

@wborn
Copy link
Member Author

wborn commented Mar 20, 2023

Everything is done now! 🥳

@wborn wborn closed this as completed Mar 20, 2023
@wborn wborn unpinned this issue Mar 20, 2023
@openhab-bot
Copy link
Collaborator

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

https://community.openhab.org/t/oh3-4-oh4-0-2/148900/20

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement An enhancement or new feature
Projects
Archived in project
Development

No branches or pull requests

5 participants