jdk/src/java.base/share/classes/java/lang/reflect/Method.java
changeset 26455 195a6f3e0cd0
parent 25859 3317bb8137f4
child 29125 83b9bf8a6c2a
--- a/jdk/src/java.base/share/classes/java/lang/reflect/Method.java	Mon Sep 08 20:29:15 2014 +0200
+++ b/jdk/src/java.base/share/classes/java/lang/reflect/Method.java	Tue Sep 09 10:48:01 2014 +0200
@@ -79,6 +79,9 @@
     // For sharing of MethodAccessors. This branching structure is
     // currently only two levels deep (i.e., one root Method and
     // potentially many Method objects pointing to it.)
+    //
+    // If this branching structure would ever contain cycles, deadlocks can
+    // occur in annotation code.
     private Method              root;
 
     // Generics infrastructure
@@ -144,6 +147,9 @@
         // which implicitly requires that new java.lang.reflect
         // objects be fabricated for each reflective call on Class
         // objects.)
+        if (this.root != null)
+            throw new IllegalArgumentException("Can not copy a non-root Method");
+
         Method res = new Method(clazz, name, parameterTypes, returnType,
                                 exceptionTypes, modifiers, slot, signature,
                                 annotations, parameterAnnotations, annotationDefault);
@@ -153,6 +159,14 @@
         return res;
     }
 
+    /**
+     * Used by Excecutable for annotation sharing.
+     */
+    @Override
+    Executable getRoot() {
+        return root;
+    }
+
     @Override
     boolean hasGenericInformation() {
         return (getGenericSignature() != null);