summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@typesafe.com>2013-04-12 13:38:42 -0700
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-05-16 11:56:20 -0700
commit7f9feba0213fc210c7752ab210f900c016032699 (patch)
tree80bcfeab588097788c6e7fe1463b74a95de0c78e
parent487584caa97d0905df06e32c292c00fcd82a2fa3 (diff)
downloadscala-7f9feba0213fc210c7752ab210f900c016032699.tar.gz
scala-7f9feba0213fc210c7752ab210f900c016032699.tar.bz2
scala-7f9feba0213fc210c7752ab210f900c016032699.zip
[backport #1727] SI-7359 cyclic nested java class
The original commit message (from 54a84a36d5): SI-6548 reflection correctly enters jinners When completing Java classes, runtime reflection enumerates their fields, methods, constructors and inner classes, loads them and enters them into either the instance part (ClassSymbol) or the static part (ModuleSymbol). However unlike fields, methods and constructors, inner classes don't need to be entered explicitly - they are entered implicitly when being loaded. This patch fixes the double-enter problem, make sure that enter-on-load uses the correct owner, and also hardens jclassAsScala against double enters that can occur in a different scenario.
-rw-r--r--src/reflect/scala/reflect/runtime/JavaMirrors.scala17
-rw-r--r--test/files/run/t6989.check84
-rw-r--r--test/files/run/t6989/JavaClass_1.java2
-rw-r--r--test/files/run/t7359.check1
-rw-r--r--test/files/run/t7359/Cyclic_1.java3
-rw-r--r--test/files/run/t7359/Test_2.scala6
6 files changed, 32 insertions, 81 deletions
diff --git a/src/reflect/scala/reflect/runtime/JavaMirrors.scala b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
index 3442e3d22e..0e06e643fb 100644
--- a/src/reflect/scala/reflect/runtime/JavaMirrors.scala
+++ b/src/reflect/scala/reflect/runtime/JavaMirrors.scala
@@ -687,7 +687,8 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
(if (jModifier.isStatic(mods)) module.moduleClass else clazz).info.decls enter sym
for (jinner <- jclazz.getDeclaredClasses) {
- enter(jclassAsScala(jinner, clazz), jinner.getModifiers)
+ jclassAsScala(jinner) // inner class is entered as a side-effect
+ // no need to call enter explicitly
}
pendingLoadActions = { () =>
@@ -1046,13 +1047,17 @@ private[reflect] trait JavaMirrors extends internal.SymbolTable with api.JavaUni
* @param jclazz The Java class
* @return A Scala class symbol that wraps all reflection info of `jclazz`
*/
- private def jclassAsScala(jclazz: jClass[_]): Symbol = jclassAsScala(jclazz, sOwner(jclazz))
+ private def jclassAsScala(jclazz: jClass[_]): Symbol = {
+ val clazz = sOwner(jclazz) // sOwner called outside of closure for binary compatibility
+ toScala(classCache, jclazz){ (mirror, jclazz) =>
+ mirror.jclassAsScala(jclazz, clazz)
+ }
+ }
private def jclassAsScala(jclazz: jClass[_], owner: Symbol): ClassSymbol = {
- val name = scalaSimpleName(jclazz)
- val completer = (clazz: Symbol, module: Symbol) => new FromJavaClassCompleter(clazz, module, jclazz)
- val (clazz, module) = createClassModule(owner, name, completer)
- classCache enter (jclazz, clazz)
+ val name = scalaSimpleName(jclazz)
+ val completer = (clazz: Symbol, module: Symbol) => new FromJavaClassCompleter(clazz, module, jclazz)
+ val (clazz, _) = createClassModule(owner, name, completer)
clazz
}
diff --git a/test/files/run/t6989.check b/test/files/run/t6989.check
index 3a94f6e8df..8943792115 100644
--- a/test/files/run/t6989.check
+++ b/test/files/run/t6989.check
@@ -113,18 +113,6 @@ isProtected = false
isPublic = false
privateWithin = <none>
============
-sym = class $PrivateJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
-isPrivate = true
-isProtected = false
-isPublic = false
-privateWithin = <none>
-============
-sym = value this$0, signature = foo.JavaClass_1, owner = class $PrivateJavaClass
-isPrivate = false
-isProtected = false
-isPublic = false
-privateWithin = package foo
-============
sym = class $ProtectedJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
isPrivate = false
isProtected = true
@@ -143,18 +131,6 @@ isProtected = false
isPublic = false
privateWithin = package foo
============
-sym = class $ProtectedJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
-isPrivate = false
-isProtected = true
-isPublic = false
-privateWithin = package foo
-============
-sym = value this$0, signature = foo.JavaClass_1, owner = class $ProtectedJavaClass
-isPrivate = false
-isProtected = false
-isPublic = false
-privateWithin = package foo
-============
sym = class $PublicJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
isPrivate = false
isProtected = false
@@ -179,97 +155,55 @@ isProtected = false
isPublic = true
privateWithin = <none>
============
-sym = class $PublicJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
-isPrivate = false
-isProtected = false
-isPublic = true
-privateWithin = <none>
-============
-sym = constructor $PublicJavaClass, signature = (x$1: foo.JavaClass_1)JavaClass_1.this.$PublicJavaClass, owner = class $PublicJavaClass
+sym = constructor JavaClass_1, signature = ()foo.JavaClass_1, owner = class JavaClass_1
isPrivate = false
isProtected = false
isPublic = true
privateWithin = <none>
============
-sym = value this$0, signature = foo.JavaClass_1, owner = class $PublicJavaClass
-isPrivate = false
-isProtected = false
-isPublic = false
-privateWithin = package foo
-============
-sym = constructor JavaClass_1, signature = ()foo.JavaClass_1, owner = class JavaClass_1
+sym = object JavaClass_1, signature = foo.JavaClass_1.type, owner = package foo
isPrivate = false
isProtected = false
isPublic = true
privateWithin = <none>
============
-sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
+sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
isPrivate = true
isProtected = false
isPublic = false
privateWithin = <none>
============
-sym = object PrivateStaticJavaClass, signature = JavaClass_1.this.PrivateStaticJavaClass.type, owner = class JavaClass_1
+sym = object PrivateStaticJavaClass, signature = foo.JavaClass_1.PrivateStaticJavaClass.type, owner = object JavaClass_1
isPrivate = true
isProtected = false
isPublic = false
privateWithin = <none>
============
-sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
+sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
isPrivate = true
isProtected = false
isPublic = false
privateWithin = <none>
============
-sym = object ProtectedStaticJavaClass, signature = JavaClass_1.this.ProtectedStaticJavaClass.type, owner = class JavaClass_1
+sym = object ProtectedStaticJavaClass, signature = foo.JavaClass_1.ProtectedStaticJavaClass.type, owner = object JavaClass_1
isPrivate = true
isProtected = false
isPublic = false
privateWithin = <none>
============
-sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
-isPrivate = false
-isProtected = false
-isPublic = true
-privateWithin = <none>
-============
-sym = constructor PublicStaticJavaClass, signature = ()JavaClass_1.this.PublicStaticJavaClass, owner = class PublicStaticJavaClass
-isPrivate = false
-isProtected = false
-isPublic = true
-privateWithin = <none>
-============
-sym = object PublicStaticJavaClass, signature = JavaClass_1.this.PublicStaticJavaClass.type, owner = class JavaClass_1
+sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = object JavaClass_1
isPrivate = false
isProtected = false
isPublic = true
privateWithin = <none>
============
-sym = object JavaClass_1, signature = foo.JavaClass_1.type, owner = package foo
-isPrivate = false
-isProtected = false
-isPublic = true
-privateWithin = <none>
-============
-sym = class PrivateStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
-isPrivate = true
-isProtected = false
-isPublic = false
-privateWithin = <none>
-============
-sym = class ProtectedStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
-isPrivate = true
-isProtected = false
-isPublic = false
-privateWithin = <none>
-============
-sym = class PublicStaticJavaClass, signature = ClassInfoType(...), owner = class JavaClass_1
+sym = constructor PublicStaticJavaClass, signature = ()foo.JavaClass_1.PublicStaticJavaClass, owner = class PublicStaticJavaClass
isPrivate = false
isProtected = false
isPublic = true
privateWithin = <none>
============
-sym = constructor PublicStaticJavaClass, signature = ()JavaClass_1.this.PublicStaticJavaClass, owner = class PublicStaticJavaClass
+sym = object PublicStaticJavaClass, signature = foo.JavaClass_1.PublicStaticJavaClass.type, owner = object JavaClass_1
isPrivate = false
isProtected = false
isPublic = true
diff --git a/test/files/run/t6989/JavaClass_1.java b/test/files/run/t6989/JavaClass_1.java
index eb26a08700..72ec4d6ab6 100644
--- a/test/files/run/t6989/JavaClass_1.java
+++ b/test/files/run/t6989/JavaClass_1.java
@@ -7,6 +7,8 @@ package foo;
// I'm leaving the incorrect results of FromJavaClassCompleters in the check
// file, so that we get notified when something changes there.
+// ^^^ It's not clear what those incorrect results were, but the fix for SI-7359
+// (backport of fix for SI-6548) has probably resolved some of these. OP, please revisit this comment.
class PackagePrivateJavaClass {
private int privateField = 0;
diff --git a/test/files/run/t7359.check b/test/files/run/t7359.check
new file mode 100644
index 0000000000..9766475a41
--- /dev/null
+++ b/test/files/run/t7359.check
@@ -0,0 +1 @@
+ok
diff --git a/test/files/run/t7359/Cyclic_1.java b/test/files/run/t7359/Cyclic_1.java
new file mode 100644
index 0000000000..42b46c1aed
--- /dev/null
+++ b/test/files/run/t7359/Cyclic_1.java
@@ -0,0 +1,3 @@
+abstract class Cyclic {
+ static interface Inner<T extends Inner> { }
+} \ No newline at end of file
diff --git a/test/files/run/t7359/Test_2.scala b/test/files/run/t7359/Test_2.scala
new file mode 100644
index 0000000000..bb6f4cb2d9
--- /dev/null
+++ b/test/files/run/t7359/Test_2.scala
@@ -0,0 +1,6 @@
+import scala.reflect.runtime.universe._
+
+object Test extends App {
+ typeOf[Cyclic].members
+ println("ok")
+} \ No newline at end of file