Exclude statics from override checks when access modifying.
Class constructors should just not be changed and static methods are not
virtually dispatched and are not qualified for any override check.
Change-Id: I3fcf4e558790223b003c44e8b3d78d981c071029
diff --git a/src/main/java/com/android/tools/r8/optimize/AccessModifier.java b/src/main/java/com/android/tools/r8/optimize/AccessModifier.java
index b2d577c..fd0cfb7 100644
--- a/src/main/java/com/android/tools/r8/optimize/AccessModifier.java
+++ b/src/main/java/com/android/tools/r8/optimize/AccessModifier.java
@@ -169,6 +169,9 @@
if (accessFlags.isPublic()) {
return false;
}
+ if (accessFlags.isConstructor() && accessFlags.isStatic()) {
+ return false;
+ }
// If this method is mentioned in keep rules, do not transform (rule applications changed).
DexEncodedMethod definition = method.getDefinition();
if (!appView.appInfo().isAccessModificationAllowed(method)) {
@@ -184,6 +187,15 @@
return false;
}
+ if (accessFlags.isStatic()) {
+ // For static methods we can just relax the access to public, since
+ // even though JLS prevents from declaring static method in derived class if
+ // an instance method with same signature exists in superclass, JVM actually
+ // does not take into account access of the static methods.
+ doPublicize(method);
+ return false;
+ }
+
if (accessFlags.isPackagePrivate()) {
// If we publicize a package private method we have to ensure there is no overrides of it. We
// could potentially publicize a method if it only has package-private overrides.
@@ -204,15 +216,6 @@
assert accessFlags.isPrivate();
- if (accessFlags.isStatic()) {
- // For private static methods we can just relax the access to public, since
- // even though JLS prevents from declaring static method in derived class if
- // an instance method with same signature exists in superclass, JVM actually
- // does not take into account access of the static methods.
- doPublicize(method);
- return false;
- }
-
// We can't publicize private instance methods in interfaces or methods that are copied from
// interfaces to lambda-desugared classes because this will be added as a new default method.
// TODO(b/111118390): It might be possible to transform it into static methods, though.