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
This commit is contained in:
Taro L. Saito 2023-01-31 10:35:03 -08:00 committed by GitHub
parent 5ad862e802
commit 39160ac5d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 2 deletions

View File

@ -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 := {

View File

@ -28,6 +28,7 @@ import java.io.IOException;
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 class Snappy
// pos limit
// [ ......BBBBBBB.........]
compressed.limit(cPos + compressedSize);
((Buffer) compressed).limit(cPos + compressedSize);
return compressedSize;
}