From 39160ac5d24540005cd589e1eaeec07aa79974b4 Mon Sep 17 00:00:00 2001 From: "Taro L. Saito" Date: Tue, 31 Jan 2023 10:35:03 -0800 Subject: [PATCH] Fix java8 compatibility (#390) * ByteBuffer.limit() compiled with JDK9+ shows java.lang.NoSuchMethodError: java.nio.ByteBuffer.limit(I)Ljava/nio/ByteBuffer; error in JDK8 * Set --release 8 JDK option * Do not use --release 8 option in JDK8 --- build.sbt | 9 ++++++++- src/main/java/org/xerial/snappy/Snappy.java | 3 ++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/build.sbt b/build.sbt index 4bf056b0..dc3bcc04 100644 --- a/build.sbt +++ b/build.sbt @@ -27,7 +27,14 @@ ThisBuild / dynverSeparator := "-" ThisBuild / scalaVersion := "2.12.11" // For building jars for JDK8 -ThisBuild / javacOptions ++= Seq("-source", "1.8", "-target", "1.8") +ThisBuild / javacOptions ++= { + if (scala.util.Properties.isJavaAtLeast("9")) { + // --release 8 option is not available in JDK8 + Seq("--release", "8") + } else { + Seq.empty + } +} Compile / compile / javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation") doc / javacOptions := { diff --git a/src/main/java/org/xerial/snappy/Snappy.java b/src/main/java/org/xerial/snappy/Snappy.java index 0c2815f0..5263e94b 100755 --- a/src/main/java/org/xerial/snappy/Snappy.java +++ b/src/main/java/org/xerial/snappy/Snappy.java @@ -28,6 +28,7 @@ import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URL; +import java.nio.Buffer; import java.nio.ByteBuffer; import java.nio.charset.Charset; import java.util.Properties; @@ -154,7 +155,7 @@ public static int compress(ByteBuffer uncompressed, ByteBuffer compressed) // pos limit // [ ......BBBBBBB.........] - compressed.limit(cPos + compressedSize); + ((Buffer) compressed).limit(cPos + compressedSize); return compressedSize; }