summaryrefslogtreecommitdiff
path: root/test/files/run/t2464
diff options
context:
space:
mode:
authorJason Zaugg <jzaugg@gmail.com>2013-06-06 19:01:48 +0200
committerJason Zaugg <jzaugg@gmail.com>2013-06-06 19:01:48 +0200
commit2a19cd56258884e25f26565d7b865cc2ec931b23 (patch)
tree699ce548bdc6a2cd63b4a4ab448036681bc7a2f8 /test/files/run/t2464
parent5312d6305530eb14d369d0f4acaf7ca4e278ea72 (diff)
downloadscala-2a19cd56258884e25f26565d7b865cc2ec931b23.tar.gz
scala-2a19cd56258884e25f26565d7b865cc2ec931b23.tar.bz2
scala-2a19cd56258884e25f26565d7b865cc2ec931b23.zip
SI-2464 Resiliance against missing InnerClass attributes
A classfile in the wild related to Vaadin lacked the InnerClasses attribute. As such, our class file parser treated a nested enum class as top-level, which led to a crash when trying to find its linked module. More details of the investigation are available in the JIRA comments. The test introduces a new facility to rewrite classfiles. This commit turns this situation into a logged warning, rather than crashing. Code by @paulp, test by yours truly.
Diffstat (limited to 'test/files/run/t2464')
-rw-r--r--test/files/run/t2464/Annotated.java5
-rw-r--r--test/files/run/t2464/Connect.java20
-rw-r--r--test/files/run/t2464/Test.scala35
3 files changed, 60 insertions, 0 deletions
diff --git a/test/files/run/t2464/Annotated.java b/test/files/run/t2464/Annotated.java
new file mode 100644
index 0000000000..d022f9852c
--- /dev/null
+++ b/test/files/run/t2464/Annotated.java
@@ -0,0 +1,5 @@
+package test;
+
+@Connect(loadStyle = Connect.LoadStyle.EAGER)
+public class Annotated {
+}
diff --git a/test/files/run/t2464/Connect.java b/test/files/run/t2464/Connect.java
new file mode 100644
index 0000000000..59349f94c8
--- /dev/null
+++ b/test/files/run/t2464/Connect.java
@@ -0,0 +1,20 @@
+package test;
+
+import java.lang.annotation.ElementType;
+import java.lang.annotation.Retention;
+import java.lang.annotation.RetentionPolicy;
+import java.lang.annotation.Target;
+
+
+@Retention(RetentionPolicy.RUNTIME)
+@Target(ElementType.TYPE)
+public @interface Connect {
+
+ LoadStyle loadStyle() default LoadStyle.EAGER;
+
+ public enum LoadStyle {
+ EAGER,
+ DEFERRED,
+ LAZY
+ }
+}
diff --git a/test/files/run/t2464/Test.scala b/test/files/run/t2464/Test.scala
new file mode 100644
index 0000000000..90e1a03c17
--- /dev/null
+++ b/test/files/run/t2464/Test.scala
@@ -0,0 +1,35 @@
+import scala.reflect.io.Streamable
+import scala.tools.asm.{ClassWriter, ClassReader}
+import scala.tools.asm.tree.ClassNode
+import scala.tools.partest._
+import scala.tools.partest.BytecodeTest.modifyClassFile
+import java.io.{FileOutputStream, FileInputStream, File}
+
+object Test extends DirectTest {
+ def code = ???
+
+ def compileCode(code: String) = {
+ val classpath = List(sys.props("partest.lib"), testOutput.path) mkString sys.props("path.separator")
+ compileString(newCompiler("-cp", classpath, "-d", testOutput.path))(code)
+ }
+
+ def app = """
+ object O {
+ new test.Annotated
+ }
+ """
+
+ def show(): Unit = {
+ compileCode(app)
+ modifyClassFile(new File(testOutput.toFile, "test/Annotated.class")) {
+ (cn: ClassNode) =>
+ // As investigated https://issues.scala-lang.org/browse/SI-2464?focusedCommentId=64521&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-64521
+ // classfiles in the wild sometimes lack the required InnerClass attribute for nested enums that
+ // are referenced in an annotation. I don't know what compiler or bytecode processor leaves things
+ // that way, but this test makes sure we don't crash.
+ cn.innerClasses.clear()
+ cn
+ }
+ compileCode(app)
+ }
+}