Version 0.1.16

Merge: edcf578bc9657aac190739aac482305b6530bc2a
CL: https://r8-review.googlesource.com/c/r8/+/8460
Change-Id: I804a8e74c451831a428b8c42098fdb682d6c2b27
diff --git a/src/main/java/com/android/tools/r8/D8.java b/src/main/java/com/android/tools/r8/D8.java
index 53f88d1..f4b3c8d 100644
--- a/src/main/java/com/android/tools/r8/D8.java
+++ b/src/main/java/com/android/tools/r8/D8.java
@@ -55,7 +55,7 @@
  */
 public final class D8 {
 
-  private static final String VERSION = "v0.1.15";
+  private static final String VERSION = "v0.1.16";
   private static final int STATUS_ERROR = 1;
 
   private D8() {}
diff --git a/src/main/java/com/android/tools/r8/R8.java b/src/main/java/com/android/tools/r8/R8.java
index f08e688..1fb04a6 100644
--- a/src/main/java/com/android/tools/r8/R8.java
+++ b/src/main/java/com/android/tools/r8/R8.java
@@ -71,7 +71,7 @@
 
 public class R8 {
 
-  private static final String VERSION = "v0.1.15";
+  private static final String VERSION = "v0.1.16";
   private final Timing timing = new Timing("R8");
   private final InternalOptions options;
 
diff --git a/src/main/java/com/android/tools/r8/graph/DexClass.java b/src/main/java/com/android/tools/r8/graph/DexClass.java
index 3f492b5..9c79d90 100644
--- a/src/main/java/com/android/tools/r8/graph/DexClass.java
+++ b/src/main/java/com/android/tools/r8/graph/DexClass.java
@@ -81,7 +81,6 @@
     virtualMethods = MoreObjects.firstNonNull(values, NO_METHODS);
   }
 
-
   public void forEachMethod(Consumer<DexEncodedMethod> consumer) {
     for (DexEncodedMethod method : directMethods()) {
       consumer.accept(method);
@@ -119,6 +118,15 @@
     staticFields = MoreObjects.firstNonNull(values, NO_FIELDS);
   }
 
+  public boolean definesStaticField(DexField field) {
+    for (DexEncodedField encodedField : staticFields()) {
+      if (encodedField.field == field) {
+        return true;
+      }
+    }
+    return false;
+  }
+
   public DexEncodedField[] instanceFields() {
     return instanceFields;
   }
diff --git a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
index cf89455..5ca8fd1 100644
--- a/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
+++ b/src/main/java/com/android/tools/r8/ir/optimize/CodeRewriter.java
@@ -663,6 +663,13 @@
     if (exit == null) {
       return;
     }
+    DexClass clazz = appInfo.definitionFor(method.method.getHolder());
+    if (clazz == null) {
+      // TODO(67672280): Synthesized lambda classes are also optimized. However, they are not
+      // added to the AppInfo.
+      assert method.accessFlags.isSynthetic();
+      return;
+    }
     Set<StaticPut> puts = Sets.newIdentityHashSet();
     Map<DexField, StaticPut> dominatingPuts = Maps.newIdentityHashMap();
     for (BasicBlock block : dominatorTree.dominatorBlocks(exit)) {
@@ -672,7 +679,7 @@
         if (current.isStaticPut()) {
           StaticPut put = current.asStaticPut();
           DexField field = put.getField();
-          if (field.getHolder() == method.method.getHolder()) {
+          if (clazz.definesStaticField(field)) {
             if (put.inValue().isConstant()) {
               if ((field.type.isClassType() || field.type.isArrayType())
                   && put.inValue().getConstInstruction().isConstNumber() &&
@@ -709,10 +716,6 @@
       for (StaticPut put : dominatingPuts.values()) {
         DexField field = put.getField();
         DexEncodedField encodedField = appInfo.definitionFor(field);
-        if (encodedField == null) {
-          // See b/67468748.
-          continue;
-        }
         if (field.type == dexItemFactory.stringType) {
           if (put.inValue().isConstant()) {
             if (put.inValue().getConstInstruction().isConstNumber()) {