From 661d922ebe49b63b010628b806723e61085e0db5 Mon Sep 17 00:00:00 2001 From: Jason Zaugg Date: Mon, 3 Feb 2020 13:27:00 +1000 Subject: [PATCH] Make junit/test pass on JDK 14 --- .../scala/lang/annotations/RunTest.scala | 8 +++--- .../scala/lang/primitives/BoxUnboxTest.scala | 2 +- .../scala/reflect/ClassBearingAnnotation.java | 13 ++++++++++ test/junit/scala/reflect/ClassOfTest.scala | 26 +++++++++---------- .../nsc/backend/jvm/opt/BoxUnboxTest.scala | 5 ++-- .../backend/jvm/opt/MethodLevelOptsTest.scala | 5 ++-- 6 files changed, 37 insertions(+), 22 deletions(-) create mode 100644 test/junit/scala/reflect/ClassBearingAnnotation.java diff --git a/test/junit/scala/lang/annotations/RunTest.scala b/test/junit/scala/lang/annotations/RunTest.scala index 0d9c0c471362..ac46ef897a20 100644 --- a/test/junit/scala/lang/annotations/RunTest.scala +++ b/test/junit/scala/lang/annotations/RunTest.scala @@ -14,15 +14,15 @@ class RunTest extends RunTesting { @Test def annotationInfoNotErased(): Unit = { val code = - """import javax.annotation.Resource + """import scala.reflect.ClassBearingAnnotation |import scala.annotation.meta.getter |class C { - | type Rg = Resource @getter - | @(Resource @getter)(`type` = classOf[Int]) def a = 0 + | type Rg = ClassBearingAnnotation @getter + | @(ClassBearingAnnotation @getter)(`type` = classOf[Int]) def a = 0 | @Rg(`type` = classOf[Int]) def b = 0 |} |val c = classOf[C] - |def typeArg(meth: String) = c.getDeclaredMethod(meth).getDeclaredAnnotation(classOf[Resource]).`type` + |def typeArg(meth: String) = c.getDeclaredMethod(meth).getDeclaredAnnotation(classOf[ClassBearingAnnotation]).`type` |List("a", "b") map typeArg |""".stripMargin diff --git a/test/junit/scala/lang/primitives/BoxUnboxTest.scala b/test/junit/scala/lang/primitives/BoxUnboxTest.scala index a35d4ec07fe5..1ec67bddef97 100644 --- a/test/junit/scala/lang/primitives/BoxUnboxTest.scala +++ b/test/junit/scala/lang/primitives/BoxUnboxTest.scala @@ -21,7 +21,7 @@ class BoxUnboxTest extends RunTesting { def genericNull[T] = null.asInstanceOf[T] // allowed, see scala/bug#4437, point 2 - val b = new Integer(1) + val b = Integer.valueOf(1) val u = 1 assertEquals(1.toInt, u) diff --git a/test/junit/scala/reflect/ClassBearingAnnotation.java b/test/junit/scala/reflect/ClassBearingAnnotation.java new file mode 100644 index 000000000000..b753028e61cb --- /dev/null +++ b/test/junit/scala/reflect/ClassBearingAnnotation.java @@ -0,0 +1,13 @@ +package scala.reflect; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +@Target({TYPE, FIELD, METHOD}) +@Retention(RUNTIME) +public @interface ClassBearingAnnotation { + Class type() default java.lang.Object.class; +} diff --git a/test/junit/scala/reflect/ClassOfTest.scala b/test/junit/scala/reflect/ClassOfTest.scala index 520b14ccd467..fe6cd513d707 100644 --- a/test/junit/scala/reflect/ClassOfTest.scala +++ b/test/junit/scala/reflect/ClassOfTest.scala @@ -71,27 +71,27 @@ class ClassOfTest extends RunTesting { @Test def t9702(): Unit = { val code = - """import javax.annotation.Resource + """import scala.reflect.ClassBearingAnnotation |import scala.reflect.ClassOfTest.VC |class C { | type aList[K] = List[K] | type aVC = VC | type aInt = Int | type aInteger = Integer - | @Resource(`type` = classOf[List[Int]]) def a = 0 - | @Resource(`type` = classOf[List[_]]) def b = 0 - | @Resource(`type` = classOf[aList[_]]) def c = 0 - | @Resource(`type` = classOf[Int]) def d = 0 - | @Resource(`type` = classOf[aInt]) def e = 0 - | @Resource(`type` = classOf[Integer]) def f = 0 - | @Resource(`type` = classOf[aInteger]) def g = 0 - | @Resource(`type` = classOf[VC]) def h = 0 - | @Resource(`type` = classOf[aVC]) def i = 0 - | @Resource(`type` = classOf[Array[Int]]) def j = 0 - | @Resource(`type` = classOf[Array[List[_]]]) def k = 0 + | @ClassBearingAnnotation(`type` = classOf[List[Int]]) def a = 0 + | @ClassBearingAnnotation(`type` = classOf[List[_]]) def b = 0 + | @ClassBearingAnnotation(`type` = classOf[aList[_]]) def c = 0 + | @ClassBearingAnnotation(`type` = classOf[Int]) def d = 0 + | @ClassBearingAnnotation(`type` = classOf[aInt]) def e = 0 + | @ClassBearingAnnotation(`type` = classOf[Integer]) def f = 0 + | @ClassBearingAnnotation(`type` = classOf[aInteger]) def g = 0 + | @ClassBearingAnnotation(`type` = classOf[VC]) def h = 0 + | @ClassBearingAnnotation(`type` = classOf[aVC]) def i = 0 + | @ClassBearingAnnotation(`type` = classOf[Array[Int]]) def j = 0 + | @ClassBearingAnnotation(`type` = classOf[Array[List[_]]]) def k = 0 |} |val c = classOf[C] - |def typeArg(meth: String) = c.getDeclaredMethod(meth).getDeclaredAnnotation(classOf[Resource]).`type` + |def typeArg(meth: String) = c.getDeclaredMethod(meth).getDeclaredAnnotation(classOf[ClassBearingAnnotation]).`type` |('a' to 'k').toList.map(_.toString).map(typeArg) """.stripMargin diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/BoxUnboxTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/BoxUnboxTest.scala index ef893b449c9f..e9692d26ab7c 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/BoxUnboxTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/BoxUnboxTest.scala @@ -8,6 +8,7 @@ import org.junit.runner.RunWith import org.junit.runners.JUnit4 import scala.tools.asm.Opcodes._ +import scala.tools.nsc.reporters.StoreReporter import scala.tools.partest.ASMConverters._ import scala.tools.testing.BytecodeTesting import scala.tools.testing.BytecodeTesting._ @@ -148,7 +149,7 @@ class BoxUnboxTest extends BytecodeTesting { |} """.stripMargin - val c = compileClass(code) + val c = compileClass(code, allowMessage = (info: StoreReporter#Info) => info.msg.contains("there were two deprecation warnings")) assertNoInvoke(getMethod(c, "t1")) assertNoInvoke(getMethod(c, "t2")) @@ -310,7 +311,7 @@ class BoxUnboxTest extends BytecodeTesting { | } |} """.stripMargin - val c = compileClass(code) + val c = compileClass(code, allowMessage = (info: StoreReporter#Info) => info.msg.contains("there was one deprecation warning")) assertNoInvoke(getMethod(c, "t1")) assertSameSummary(getMethod(c, "t2"), List(ICONST_1, ICONST_3, IADD, IRETURN)) assertSameSummary(getMethod(c, "t3"), List(ICONST_3, ICONST_4, IADD, IRETURN)) diff --git a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala index 87bd5a79d94d..b47be29f1fba 100644 --- a/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala +++ b/test/junit/scala/tools/nsc/backend/jvm/opt/MethodLevelOptsTest.scala @@ -11,6 +11,7 @@ import scala.collection.JavaConverters._ import scala.tools.asm.Opcodes._ import scala.tools.asm.tree.ClassNode import scala.tools.nsc.backend.jvm.AsmUtils._ +import scala.tools.nsc.reporters.StoreReporter import scala.tools.partest.ASMConverters._ import scala.tools.testing.BytecodeTesting import scala.tools.testing.BytecodeTesting._ @@ -158,7 +159,7 @@ class MethodLevelOptsTest extends BytecodeTesting { | } |} """.stripMargin - val c = compileClass(code) + val c = compileClass(code, allowMessage = (info: StoreReporter#Info) => info.msg.contains("there was one deprecation warning")) assertSameCode(getMethod(c, "t"), List( IntOp(BIPUSH, 23), IntOp(NEWARRAY, 5), Op(POP), VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN))) } @@ -173,7 +174,7 @@ class MethodLevelOptsTest extends BytecodeTesting { | } |} """.stripMargin - val c = compileClass(code) + val c = compileClass(code, allowMessage = (info: StoreReporter#Info) => info.msg.contains("there was one deprecation warning")) assertSameCode(getMethod(c, "t"), List( TypeOp(NEW, "java/lang/Integer"), Ldc(LDC, "nono"), Invoke(INVOKESPECIAL, "java/lang/Integer", "", "(Ljava/lang/String;)V", false), VarOp(ILOAD, 1), VarOp(ILOAD, 2), Op(IADD), Op(IRETURN)))