Companion class must be public
- Companion classes used when we desugar default methods must be
public so moved methods can be called from anywhere, otherwise
runtime can generate IllegalAccessError in some cases.
Change-Id: I3496934baf3c8f56db53d6e598fa1405e71e03b0
diff --git a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java
index 772d74c..66cd7d9 100644
--- a/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/desugar/InterfaceProcessor.java
@@ -121,6 +121,8 @@
companionClassFlags.unsetInterface();
companionClassFlags.setFinal();
companionClassFlags.setSynthetic();
+ // Companion class must be public so moved methods can be called from anywhere.
+ companionClassFlags.setPublic();
// Create companion class.
DexType companionClassType = rewriter.getCompanionClassType(iface.type);
diff --git a/src/test/examplesAndroidN/interfacemethods/DefaultMethods.java b/src/test/examplesAndroidN/interfacemethods/DefaultMethods.java
index ef49f4e..25e3fea 100644
--- a/src/test/examplesAndroidN/interfacemethods/DefaultMethods.java
+++ b/src/test/examplesAndroidN/interfacemethods/DefaultMethods.java
@@ -4,6 +4,8 @@
package interfacemethods;
+import interfacemethods.p1.I4;
+
public class DefaultMethods {
interface I3 {
@@ -22,8 +24,12 @@
static class C4 extends C3 implements I3 {
}
+ static class C5 implements I4 {
+ }
+
public static void main(String[] args) {
new C2().d1();
System.out.println(new C4().getValue());
+ new C5().dump();
}
}
diff --git a/src/test/examplesAndroidN/interfacemethods/p1/I3.java b/src/test/examplesAndroidN/interfacemethods/p1/I3.java
new file mode 100644
index 0000000..f956279
--- /dev/null
+++ b/src/test/examplesAndroidN/interfacemethods/p1/I3.java
@@ -0,0 +1,12 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package interfacemethods.p1;
+
+interface I3 {
+
+ default void dump() {
+ System.out.println("I3");
+ }
+}
diff --git a/src/test/examplesAndroidN/interfacemethods/p1/I4.java b/src/test/examplesAndroidN/interfacemethods/p1/I4.java
new file mode 100644
index 0000000..1bb946b
--- /dev/null
+++ b/src/test/examplesAndroidN/interfacemethods/p1/I4.java
@@ -0,0 +1,8 @@
+// Copyright (c) 2017, the R8 project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+package interfacemethods.p1;
+
+public interface I4 extends I3 {
+}