Skip to content

Commit

Permalink
Fix java8 compatibility (#390)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
xerial authored Jan 31, 2023
1 parent 5ad862e commit 39160ac
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
9 changes: 8 additions & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -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 := {
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/xerial/snappy/Snappy.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 39160ac

Please sign in to comment.