Version 1.4.58
Cherry pick: Disable logging when unexpected types flow to ServiceLoader.load()
CL: https://r8-review.googlesource.com/c/r8/+/34575
Cherry pick: Add check of null on receiver for extra methods when class-inlining
CL: https://r8-review.googlesource.com/c/r8/+/34652
Cherry pick: Remove ':' from NPE name for ExtraMethodNullTest
CL: https://r8-review.googlesource.com/c/r8/+/34680
Bug: 124842076, 124181030
Change-Id: Ia229a2cf90a219ec880b0ddd83db3ca16e1e7098
diff --git a/src/main/java/com/android/tools/r8/Version.java b/src/main/java/com/android/tools/r8/Version.java
index 9f06013..417e032 100644
--- a/src/main/java/com/android/tools/r8/Version.java
+++ b/src/main/java/com/android/tools/r8/Version.java
@@ -11,7 +11,7 @@
// This field is accessed from release scripts using simple pattern matching.
// Therefore, changing this field could break our release scripts.
- public static final String LABEL = "1.4.57";
+ public static final String LABEL = "1.4.58";
private Version() {
}
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java b/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java
index d6ca0e0..5c0e9c1 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/classinliner/InlineCandidateProcessor.java
@@ -729,8 +729,17 @@
List<Value> arguments = Lists.newArrayList(invoke.inValues());
// If we got here with invocation on receiver the user is ineligible.
- if (invoke.isInvokeMethodWithReceiver() && arguments.get(0) == eligibleInstance) {
- return false;
+ if (invoke.isInvokeMethodWithReceiver()) {
+ if (arguments.get(0) == eligibleInstance) {
+ return false;
+ }
+
+ // TODO(b/124842076) Extend this check to use checksNullReceiverBeforeAnySideEffect.
+ InvokeMethodWithReceiver invokeMethodWithReceiver = invoke.asInvokeMethodWithReceiver();
+ Value receiver = invokeMethodWithReceiver.getReceiver();
+ if (receiver.getTypeLattice().nullability().isNullable()) {
+ return false;
+ }
}
OptimizationInfo optimizationInfo = singleTarget.getOptimizationInfo();
diff --git a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
index e4d2cec..0c00618 100644
--- a/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
+++ b/src/main/java/com/android/tools/r8/shaking/Enqueuer.java
@@ -1825,14 +1825,16 @@
DexType serviceType = argument.definition.asConstClass().getValue();
if (!appView.appServices().allServiceTypes().contains(serviceType)) {
// Should never happen.
- options.reporter.warning(
- new StringDiagnostic(
- "The type `"
- + serviceType.toSourceString()
- + "` is being passed to the method `"
- + invoke.getInvokedMethod()
- + "`, but could was found in `META-INF/services/`.",
- appInfo.originFor(method.method.holder)));
+ if (Log.ENABLED) {
+ options.reporter.warning(
+ new StringDiagnostic(
+ "The type `"
+ + serviceType.toSourceString()
+ + "` is being passed to the method `"
+ + invoke.getInvokedMethod().toSourceString()
+ + "`, but was not found in `META-INF/services/`.",
+ appInfo.originFor(method.method.holder)));
+ }
return;
}
diff --git a/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ExtraMethodNullTest.java b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ExtraMethodNullTest.java
new file mode 100644
index 0000000..42b0ce4
--- /dev/null
+++ b/src/test/java/com/android/tools/r8/ir/optimize/classinliner/ExtraMethodNullTest.java
@@ -0,0 +1,41 @@
+// Copyright (c) 2019, 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 com.android.tools.r8.ir.optimize.classinliner;
+
+import static org.hamcrest.CoreMatchers.containsString;
+
+import com.android.tools.r8.CompilationFailedException;
+import com.android.tools.r8.NeverInline;
+import com.android.tools.r8.TestBase;
+import java.io.IOException;
+import org.junit.Test;
+
+public class ExtraMethodNullTest extends TestBase {
+
+ @Test
+ public void test() throws IOException, CompilationFailedException {
+ testForR8(Backend.DEX)
+ .addProgramClassesAndInnerClasses(One.class)
+ .addKeepMainRule(One.class)
+ .run(One.class)
+ .assertFailureWithErrorThatMatches(containsString("java.lang.NullPointerException"));
+ }
+
+ public static class One {
+
+ public static void main(String[] args) {
+ One one = new One();
+ Other other = args.length == 0 ? null : new Other();
+ other.print(one);
+ }
+
+ static class Other {
+ @NeverInline
+ Object print(Object one) {
+ return one;
+ }
+ }
+ }
+}