# HG changeset patch
# User Liam Miller-Cushon <cushon@google.com>
# Date 1438629687 25200
#      Mon Aug 03 12:21:27 2015 -0700
# Node ID 6193197d454b8e6537d7d2c62295a7e2e413bfc4
# Parent  7eef740c1482961854d423f61ace7eee1c5da362
Fix issue with hypothetical bridges and JDK-6342411

diff -r 7eef740c1482 -r 6193197d454b src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java
--- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java	Mon Aug 03 13:28:39 2015 +0200
+++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/TransTypes.java	Mon Aug 03 12:21:27 2015 -0700
@@ -354,16 +354,18 @@
                 bridge == meth ||
                 (impl != null && !bridge.owner.isSubClass(impl.owner, types))) {
                 // No bridge was added yet.
-                if (impl != null && isBridgeNeeded(meth, impl, origin.type)) {
-                    addBridge(pos, meth, impl, origin, bridge==impl, bridges);
-                } else if (impl == meth
-                           && impl.owner != origin
-                           && (impl.flags() & FINAL) == 0
-                           && (meth.flags() & (ABSTRACT|PUBLIC)) == PUBLIC
-                           && (origin.flags() & PUBLIC) > (impl.owner.flags() & PUBLIC)) {
-                    // this is to work around a horrible but permanent
-                    // reflection design error.
-                    addBridge(pos, meth, impl, origin, false, bridges);
+                boolean isNeeded = impl != null && isBridgeNeeded(meth, impl, origin.type);
+                // a bridge is needed to work around a horrible but permanent
+                // reflection design error (see JDK-6342411).
+                boolean isNeededForJDK6342411 =
+                    impl == meth
+                    && impl.owner != origin
+                    && (impl.flags() & FINAL) == 0
+                    && (meth.flags() & (ABSTRACT|PUBLIC)) == PUBLIC
+                    && (origin.flags() & PUBLIC) > (impl.owner.flags() & PUBLIC);
+                if (isNeeded || isNeededForJDK6342411) {
+                    boolean hypothetical = !isNeededForJDK6342411 && (bridge==impl);
+                    addBridge(pos, meth, impl, origin, hypothetical, bridges);
                 }
             } else if ((bridge.flags() & (SYNTHETIC | OVERRIDE_BRIDGE)) == SYNTHETIC) {
                 MethodSymbol other = overridden.get(bridge);
diff -r 7eef740c1482 -r 6193197d454b test/tools/javac/HypotheticalBridge6342411/HypotheticalBridge6342411.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/HypotheticalBridge6342411/HypotheticalBridge6342411.java	Mon Aug 03 12:21:27 2015 -0700
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/*
+ * @test
+ * @bug 6342411
+ * @summary Add bridge method to allow reflective access to public method in non-public class
+ * @author  Liam Miller-Cushon
+ * @compile p/I.java p/A.java p/B.java HypotheticalBridge6342411.java
+ * @run main HypotheticalBridge6342411
+ */
+
+import java.lang.reflect.Method;
+
+public class HypotheticalBridge6342411 {
+    public static void main(String[] args) throws Exception {
+        Method m = Class.forName("p.B").getMethod("f", Object.class);
+        p.B b = new p.B();
+        m.invoke(b, new Object[]{null});
+    }
+}
diff -r 7eef740c1482 -r 6193197d454b test/tools/javac/HypotheticalBridge6342411/p/A.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/HypotheticalBridge6342411/p/A.java	Mon Aug 03 12:21:27 2015 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p;
+
+class A<T> implements I<T> {
+    public void f(T t) {}
+}
diff -r 7eef740c1482 -r 6193197d454b test/tools/javac/HypotheticalBridge6342411/p/B.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/HypotheticalBridge6342411/p/B.java	Mon Aug 03 12:21:27 2015 -0700
@@ -0,0 +1,26 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p;
+
+public class B extends A<String> {}
diff -r 7eef740c1482 -r 6193197d454b test/tools/javac/HypotheticalBridge6342411/p/I.java
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/tools/javac/HypotheticalBridge6342411/p/I.java	Mon Aug 03 12:21:27 2015 -0700
@@ -0,0 +1,28 @@
+/*
+ * Copyright 2015 Google Inc. All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+package p;
+
+public interface I<T> {
+    void f(T t);
+}
