Skip to content

Commit 39160ac

Browse files
authored
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
1 parent 5ad862e commit 39160ac

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

build.sbt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,14 @@ ThisBuild / dynverSeparator := "-"
2727
ThisBuild / scalaVersion := "2.12.11"
2828

2929
// For building jars for JDK8
30-
ThisBuild / javacOptions ++= Seq("-source", "1.8", "-target", "1.8")
30+
ThisBuild / javacOptions ++= {
31+
if (scala.util.Properties.isJavaAtLeast("9")) {
32+
// --release 8 option is not available in JDK8
33+
Seq("--release", "8")
34+
} else {
35+
Seq.empty
36+
}
37+
}
3138
Compile / compile / javacOptions ++= Seq("-encoding", "UTF-8", "-Xlint:unchecked", "-Xlint:deprecation")
3239

3340
doc / javacOptions := {

src/main/java/org/xerial/snappy/Snappy.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import java.io.InputStream;
2929
import java.io.UnsupportedEncodingException;
3030
import java.net.URL;
31+
import java.nio.Buffer;
3132
import java.nio.ByteBuffer;
3233
import java.nio.charset.Charset;
3334
import java.util.Properties;
@@ -154,7 +155,7 @@ public static int compress(ByteBuffer uncompressed, ByteBuffer compressed)
154155

155156
// pos limit
156157
// [ ......BBBBBBB.........]
157-
compressed.limit(cPos + compressedSize);
158+
((Buffer) compressed).limit(cPos + compressedSize);
158159

159160
return compressedSize;
160161
}

0 commit comments

Comments
 (0)