Skip to content

Support building on Java 9+ #242

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
SethTisue opened this issue Jun 13, 2018 · 3 comments
Closed

Support building on Java 9+ #242

SethTisue opened this issue Jun 13, 2018 · 3 comments
Labels

Comments

@SethTisue
Copy link
Contributor

it would be nice if better-files were buildable on Java 9, even if the default build remains on Java 8. (we're trying to get the Scala 2.12 community build going on Java 9, to test Scala.)

here's a start:

diff --git a/.sbtopts b/.sbtopts
index 98d4acc..e83ea75 100644
--- a/.sbtopts
+++ b/.sbtopts
@@ -1,5 +1,4 @@
 -J-Xmx1G
--J-XX:+UseG1GC
 -J-XX:ReservedCodeCacheSize=256M
 -J-XX:MetaspaceSize=256M
 -J-XX:MaxMetaspaceSize=512M
diff --git a/core/src/main/scala/better/files/ReaderInputStream.scala b/core/src/main/scala/better/files/ReaderInputStream.scala
index 8d5e79e..f047b38 100644
--- a/core/src/main/scala/better/files/ReaderInputStream.scala
+++ b/core/src/main/scala/better/files/ReaderInputStream.scala
@@ -38,7 +38,7 @@ class ReaderInputStream(reader: Reader, encoder: CharsetEncoder, bufferSize: Int
   private[this] def fillBuffer() = {
     assert(!endOfInput)
     if (lastCoderResult.isUnderflow) {
-      val position = encoderIn.compact().position
+      val position = encoderIn.compact().position()
       //  We don't use Reader#read(CharBuffer) here because it is more efficient to write directly to the underlying char array
       // since the default implementation copies data to a temporary char array anyway
       reader.read(encoderIn.array, position, encoderIn.remaining) match {
diff --git a/core/src/main/scala/better/files/WriterOutputStream.scala b/core/src/main/scala/better/files/WriterOutputStream.scala
index b8c01e9..af7b6d8 100644
--- a/core/src/main/scala/better/files/WriterOutputStream.scala
+++ b/core/src/main/scala/better/files/WriterOutputStream.scala
@@ -81,8 +81,8 @@ class WriterOutputStream(writer: Writer, decoder: CharsetDecoder, bufferSize: In
   }
 
   private[this] def flushOutput(): Unit = {
-    if (decoderOut.position > 0) {
-      writer.write(decoderOut.array, 0, decoderOut.position)
+    if (decoderOut.position() > 0) {
+      writer.write(decoderOut.array, 0, decoderOut.position())
       val _ = decoderOut.rewind()
     }
   }

the code changes are to disambiguate between new overloads

the GC flags change is because:

Conflicting collector combinations in option list; please refer to the release notes for the combinations allowed
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.

whether there's a better resolution than dropping -XX:+UseG1GC, I don't know.

but then that leaves one compilation error:

[error] /Users/tisue/better-files/core/src/main/scala/better/files/Implicits.scala:127:37: method getProxyClass in class Proxy is deprecated: see corresponding Javadoc for more information.
[error]             java.lang.reflect.Proxy.getProxyClass(
[error]                                     ^

that I don't know, offhand, how to deal with

@pathikrit
Copy link
Owner

pathikrit commented Jun 13, 2018

Sure! How do I specify the JDK to use in build.sbt?? Or is that something I do in Travis CI by specifying multiple JDKs?

@pathikrit pathikrit changed the title support building on Java 9 Support building on Java 9+ Jun 13, 2018
pathikrit added a commit that referenced this issue Jun 13, 2018
@SethTisue
Copy link
Contributor Author

Or is that something I do in Travis CI

yes, exactly. (I see you have some publishing stuff in your .travis.yml, not sure under what conditions that stuff triggers, but you might need to explicitly disable publishing except on JDK 8)

@pathikrit
Copy link
Owner

It now passes on following JDKs:

  - oraclejdk6
  - oraclejdk7
  - oraclejdk8
  - oraclejdk9
  - oraclejdk10
  - openjdk6
  - openjdk8
  - openjdk9
  - openjdk10

Can you tell me why it is failing on openjdk7 though??

image

pathikrit added a commit that referenced this issue Jun 14, 2018
Fix #242: Add support for JDK 9 and JDK 10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants