openhab / openhab1-addons

Add-ons for openHAB 1.x
Eclipse Public License 2.0
3.43k stars 1.69k forks source link

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

Closed wborn closed 6 years ago

wborn commented 6 years ago

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 (https://github.com/openhab/openhab-distro/issues/768), we need to upgrade the rrd4j library to a version which contains the fix for https://github.com/rrd4j/rrd4j/issues/72.

So far the fix seems to be working well when updating the rrd4j JAR to the current (unreleased) master (https://github.com/openhab/openhab-distro/pull/761#issuecomment-421546648).

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

wborn commented 6 years ago

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.

fbacchella commented 6 years ago

RRD4j 3.3 that solve this issue has been released.

wborn commented 6 years ago

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 https://github.com/apache/felix/pull/114.

fbacchella commented 6 years ago

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 commented 6 years ago

It's should be resolved in 3.3.1.

wborn commented 6 years ago

Thanks a lot @fbacchella! The new version works well with both Java 8 and 11. :+1: So I've created a PR https://github.com/openhab/openhab1-addons/pull/5675 to integrate it.