Skip to content

Commit a19f53c

Browse files
committed
Method java.lang.Class#newInstance deprecated in Java 9
Switching to java.lang.reflect.Constructor#newInstance. According to Javadoc for java.lang.Class#newInstance, "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()
1 parent ccf4236 commit a19f53c

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

jvm/src/main/scala/org/scalacheck/Platform.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private[scalacheck] object Platform {
6363

6464
def newInstance(name: String, loader: ClassLoader, paramTypes: Seq[Class[_]])(args: Seq[AnyRef]): AnyRef =
6565
if(!args.isEmpty) ???
66-
else Class.forName(name, true, loader).newInstance.asInstanceOf[AnyRef]
66+
else Class.forName(name, true, loader).getDeclaredConstructor().newInstance().asInstanceOf[AnyRef]
6767

6868
def loadModule(name: String, loader: ClassLoader): AnyRef =
6969
Class.forName(name + "$", true, loader).getField("MODULE$").get(null)

0 commit comments

Comments
 (0)