typelevel / scalacheck

Property-based testing for Scala
http://www.scalacheck.org
BSD 3-Clause "New" or "Revised" License
1.94k stars 404 forks source link

Compiling on Java 9 fails #406

Closed ashawley closed 6 years ago

ashawley commented 6 years ago

Just noticed that compiling with Java 9 gives a deprecation error:

[error] jvm/src/main/scala/org/scalacheck/Platform.scala:66:44: method newInstance in class Class
[error] is deprecated: see corresponding Javadoc for more information.
[error]     else Class.forName(name, true, loader).newInstance.asInstanceOf[AnyRef]
[error]                                            ^
[error] one error found
[error] (jvm / Compile / compileIncremental) Compilation failed
[error] Total time: 31 s, completed May 3, 2018, 8:52:03 AM

Presumably, this is because both -deprecation and -Xfatal-warnings is enabled for the compiler.

ashawley commented 6 years ago

Apparently, the method is marked as deprecated in Java 9:

https://docs.oracle.com/javase/10/docs/api/java/lang/Class.html#newInstance()

According to Javadoc,

This method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException. The call

    clazz.newInstance()

can be replaced by

    clazz.getDeclaredConstructor().newInstance()