Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

[RRD4j] NoSuchMethodError when using Java 9/10/11 #5663

Closed
wborn opened this issue Sep 17, 2018 · 6 comments · Fixed by #5675
Closed

[RRD4j] NoSuchMethodError when using Java 9/10/11 #5663

wborn opened this issue Sep 17, 2018 · 6 comments · Fixed by #5675

Comments

@wborn
Copy link
Member

wborn commented Sep 17, 2018

When using the RRD4j persistence add-on with newer Java versions (9/10/11) the following NoSuchMethodErrors are logged:

Exception in thread "items-7" java.lang.NoSuchMethodError: sun.nio.ch.DirectBuffer.cleaner()Lsun/misc/Cleaner;
	at org.rrd4j.core.RrdNioBackend.unmapFile(Unknown Source)
	at org.rrd4j.core.RrdNioBackend.close(Unknown Source)
	at org.rrd4j.core.RrdDb.close(Unknown Source)
	at org.openhab.persistence.rrd4j.internal.RRD4jService.store(RRD4jService.java:175)
	at org.openhab.core.persistence.internal.PersistenceServiceDelegate.store(PersistenceServiceDelegate.java:55)
	at org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl.handleStateEvent(PersistenceManagerImpl.java:137)
	at org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl.stateChanged(PersistenceManagerImpl.java:442)
	at org.eclipse.smarthome.core.items.GenericItem$1.run(GenericItem.java:251)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
	at java.base/java.lang.Thread.run(Thread.java:834)

As a result it's not possible to store/read data in a RRD database with the add-on.

This is a very visible issue for new openHAB users because the RRD4j persistence add-on is used as chart data source in the Demo.

To support Java 11 (openhab/openhab-distro#768), we need to upgrade the rrd4j library to a version which contains the fix for rrd4j/rrd4j#72.

So far the fix seems to be working well when updating the rrd4j JAR to the current (unreleased) master (openhab/openhab-distro#761 (comment)).

There is currently no released rrd4j version that contains this fix.

@wborn
Copy link
Member Author

wborn commented Sep 21, 2018

Here's the org.openhab.persistence.rrd4j-1.13.0-SNAPSHOT.jar that can be used for testing the latest RRD4J master (3.2-SNAPSHOT) with openHAB 2.4.0-SNAPSHOT on Java 9/10/11. The bundle worked for me with both Java 8 and Java 11.

wborn referenced this issue in rrd4j/rrd4j Sep 22, 2018
…net/browse/JDK-8171377).

But Only works in Java9+, so needs a multi-release jar or dropping Java8-.

In a custom branch until I found a way to build a multi-release jar.
@fbacchella
Copy link

RRD4j 3.3 that solve this issue has been released.

@wborn
Copy link
Member Author

wborn commented Sep 29, 2018

Thanks for the new release @fbacchella! There does seem to be an issue now when using rrd4j-3.3.jar on Java 8:

22:22:50.556 [ERROR] [rg.eclipse.smarthome.core.persistence] - bundle org.eclipse.smarthome.core.persistence:0.10.0.201809271800 (105)[org.eclipse.smarthome.core.persistence.internal.PersistenceManagerImpl(271)] : The addPersistenceService method has thrown an exception
java.lang.NoSuchMethodError: java.nio.MappedByteBuffer.position(I)Ljava/nio/MappedByteBuffer;
	at org.rrd4j.core.RrdNioBackend.read(RrdNioBackend.java:172) ~[?:?]
	at org.rrd4j.core.RrdBackend.readString(RrdBackend.java:304) ~[?:?]
	at org.rrd4j.core.RrdPrimitive.readString(RrdPrimitive.java:87) ~[?:?]
	at org.rrd4j.core.RrdString.get(RrdString.java:33) ~[?:?]
	at org.rrd4j.core.Header.isRrd4jHeader(Header.java:216) ~[?:?]
	at org.rrd4j.core.Header.validateHeader(Header.java:220) ~[?:?]
	at org.rrd4j.core.RrdDb.<init>(RrdDb.java:277) ~[?:?]
	at org.rrd4j.core.RrdDb.<init>(RrdDb.java:204) ~[?:?]
	at org.rrd4j.core.RrdDb.<init>(RrdDb.java:233) ~[?:?]
	at org.openhab.persistence.rrd4j.internal.RRD4jService.getDB(RRD4jService.java:258) ~[?:?]

I think it is caused because the JAR was compiled with Java 11. When I compile the 3.3 tag with Java 8 it works on both Java 8 and Java 11. That's also how I've been testing the new code. After searching for the exception it looks very similar to the issue fixed in apache/felix#114.

@fbacchella
Copy link

Indeed:

JAVA_HOME=<JAVA9> mvn clean compile ; JAVA_HOME=<JAVA1.8> mvn verify  -Dmaven.main.skip

fails with the same exception.

JAVA_HOME=<JAVA11> mvn clean compile ; JAVA_HOME=<JAVA9> mvn verify  -Dmaven.main.skip

works.

But the patch tried by felix don't works for me. I'll keep investigating, but I'm afraid I will fail back to compile with Java8.

@fbacchella
Copy link

It's should be resolved in 3.3.1.

@wborn
Copy link
Member Author

wborn commented Oct 6, 2018

Thanks a lot @fbacchella! The new version works well with both Java 8 and 11. 👍
So I've created a PR #5675 to integrate it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants