New Upstream Release - google-auto-common-java

Ready changes

Summary

Merged new upstream version: 1.2.1 (was: 1.1.2).

Resulting package

Built on 2023-05-01T01:22 (took 11m50s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-releases libgoogle-auto-common-java

Lintian Result

Diff

diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index ec92243..c9fb8ae 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -18,11 +18,11 @@ jobs:
     steps:
       # Cancel any previous runs for the same branch that are still running.
       - name: 'Cancel previous runs'
-        uses: styfle/cancel-workflow-action@0.9.0
+        uses: styfle/cancel-workflow-action@0.9.1
         with:
           access_token: ${{ github.token }}
       - name: 'Check out repository'
-        uses: actions/checkout@v2.3.4
+        uses: actions/checkout@v2.4.0
       - name: 'Cache local Maven repository'
         uses: actions/cache@v2.1.6
         with:
@@ -49,7 +49,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: 'Check out repository'
-        uses: actions/checkout@v2.3.4
+        uses: actions/checkout@v2.4.0
       - name: 'Cache local Maven repository'
         uses: actions/cache@v2.1.6
         with:
@@ -78,7 +78,7 @@ jobs:
     runs-on: ubuntu-latest
     steps:
       - name: 'Check out repository'
-        uses: actions/checkout@v2.3.4
+        uses: actions/checkout@v2.4.0
       - name: 'Cache local Maven repository'
         uses: actions/cache@v2.1.6
         with:
diff --git a/common/pom.xml b/common/pom.xml
index ce25f9e..3996d77 100644
--- a/common/pom.xml
+++ b/common/pom.xml
@@ -26,7 +26,7 @@
 
   <groupId>com.google.auto</groupId>
   <artifactId>auto-common</artifactId>
-  <version>1.1.2</version>
+  <version>1.2.1</version>
   <name>Auto Common Libraries</name>
   <description>
     Common utilities for creating annotation processors.
@@ -36,7 +36,7 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <java.version>1.8</java.version>
-    <guava.version>30.1.1-jre</guava.version>
+    <guava.version>31.0.1-jre</guava.version>
     <truth.version>1.1.3</truth.version>
   </properties>
 
@@ -128,7 +128,7 @@
           <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-java</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.0</version>
           </dependency>
         </dependencies>
       </plugin>
diff --git a/common/src/main/java/com/google/auto/common/Overrides.java b/common/src/main/java/com/google/auto/common/Overrides.java
index 775c304..cdcd741 100644
--- a/common/src/main/java/com/google/auto/common/Overrides.java
+++ b/common/src/main/java/com/google/auto/common/Overrides.java
@@ -117,7 +117,7 @@ abstract class Overrides {
         // can't be overridden.
         return false;
       }
-      if (!(overridden.getEnclosingElement() instanceof TypeElement)) {
+      if (!MoreElements.isType(overridden.getEnclosingElement())) {
         return false;
         // We don't know how this could happen but we avoid blowing up if it does.
       }
@@ -170,9 +170,14 @@ abstract class Overrides {
           return false;
         }
       } else {
-        return in.getKind().isInterface();
-        // Method mI in or inherited by interface I (JLS 9.4.1.1). We've already checked everything.
+        // Method mI in or inherited by interface I (JLS 9.4.1.1). We've already checked everything,
+        // except that `overrider` must also be in a subinterface of `overridden`.
         // If this is not an interface then we don't know what it is so we say no.
+        TypeElement overriderType = MoreElements.asType(overrider.getEnclosingElement());
+        return in.getKind().isInterface()
+            && typeUtils.isSubtype(
+                typeUtils.erasure(overriderType.asType()),
+                typeUtils.erasure(overriddenType.asType()));
       }
     }
 
diff --git a/common/src/main/java/com/google/auto/common/Visibility.java b/common/src/main/java/com/google/auto/common/Visibility.java
index 36f4ad6..db15f8b 100644
--- a/common/src/main/java/com/google/auto/common/Visibility.java
+++ b/common/src/main/java/com/google/auto/common/Visibility.java
@@ -16,10 +16,10 @@
 package com.google.auto.common;
 
 import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Comparators.min;
 import static javax.lang.model.element.ElementKind.PACKAGE;
 
 import com.google.common.base.Enums;
+import com.google.common.collect.Ordering;
 import java.util.Set;
 import javax.lang.model.element.Element;
 import javax.lang.model.element.ElementKind;
@@ -77,7 +77,9 @@ public enum Visibility {
     Visibility effectiveVisibility = PUBLIC;
     Element currentElement = element;
     while (currentElement != null) {
-      effectiveVisibility = min(effectiveVisibility, ofElement(currentElement));
+      // NOTE: We don't use Guava's Comparators.min() because that requires Guava 30, which would
+      // make this library unusable in annotation processors using Bazel < 5.0.
+      effectiveVisibility = Ordering.natural().min(effectiveVisibility, ofElement(currentElement));
       currentElement = currentElement.getEnclosingElement();
     }
     return effectiveVisibility;
diff --git a/common/src/test/java/com/google/auto/common/MoreElementsTest.java b/common/src/test/java/com/google/auto/common/MoreElementsTest.java
index b98b79b..eaa504a 100644
--- a/common/src/test/java/com/google/auto/common/MoreElementsTest.java
+++ b/common/src/test/java/com/google/auto/common/MoreElementsTest.java
@@ -388,40 +388,6 @@ public class MoreElementsTest {
         .inOrder();
   }
 
-  static class Injectable {}
-
-  public static class MenuManager {
-    public interface ParentComponent extends MenuItemA.ParentComponent, MenuItemB.ParentComponent {}
-  }
-
-  public static class MenuItemA {
-    public interface ParentComponent {
-      Injectable injectable();
-    }
-  }
-
-  public static class MenuItemB {
-    public interface ParentComponent {
-      Injectable injectable();
-    }
-  }
-
-  public static class Main {
-    public interface ParentComponent extends MenuManager.ParentComponent {}
-  }
-
-  // Example from https://github.com/williamlian/daggerbug
-  @Test
-  public void getLocalAndInheritedMethods_DaggerBug() {
-    TypeElement main = elements.getTypeElement(Main.ParentComponent.class.getCanonicalName());
-    Set<ExecutableElement> methods =
-        MoreElements.getLocalAndInheritedMethods(main, compilation.getTypes(), elements);
-    assertThat(methods).hasSize(1);
-    ExecutableElement method = methods.iterator().next();
-    assertThat(method.getSimpleName().toString()).isEqualTo("injectable");
-    assertThat(method.getParameters()).isEmpty();
-  }
-
   private Set<ExecutableElement> visibleMethodsFromObject() {
     Types types = compilation.getTypes();
     TypeMirror intMirror = types.getPrimitiveType(TypeKind.INT);
diff --git a/common/src/test/java/com/google/auto/common/OverridesTest.java b/common/src/test/java/com/google/auto/common/OverridesTest.java
index c5ccc5f..8d77fc7 100644
--- a/common/src/test/java/com/google/auto/common/OverridesTest.java
+++ b/common/src/test/java/com/google/auto/common/OverridesTest.java
@@ -79,8 +79,8 @@ import org.junit.runners.model.Statement;
 @RunWith(Parameterized.class)
 public class OverridesTest {
   @Parameterized.Parameters(name = "{0}")
-  public static ImmutableList<CompilerType> data() {
-    return ImmutableList.of(CompilerType.JAVAC, CompilerType.ECJ);
+  public static CompilerType[] data() {
+    return CompilerType.values();
   }
 
   @Rule public CompilationRule compilation = new CompilationRule();
@@ -133,12 +133,16 @@ public class OverridesTest {
       void m(String x);
 
       void n();
+
+      Number number();
     }
 
     interface Two {
       void m();
 
       void m(int x);
+
+      Integer number();
     }
 
     static class Parent {
@@ -156,6 +160,11 @@ public class OverridesTest {
 
       @Override
       public void n() {}
+
+      @Override
+      public Number number() {
+        return 0;
+      }
     }
 
     static class ChildOfOneAndTwo implements One, Two {
@@ -170,6 +179,11 @@ public class OverridesTest {
 
       @Override
       public void n() {}
+
+      @Override
+      public Integer number() {
+        return 0;
+      }
     }
 
     static class ChildOfParentAndOne extends Parent implements One {
@@ -181,6 +195,11 @@ public class OverridesTest {
 
       @Override
       public void n() {}
+
+      @Override
+      public Number number() {
+        return 0;
+      }
     }
 
     static class ChildOfParentAndOneAndTwo extends Parent implements One, Two {
@@ -192,6 +211,11 @@ public class OverridesTest {
 
       @Override
       public void n() {}
+
+      @Override
+      public Integer number() {
+        return 0;
+      }
     }
 
     abstract static class AbstractChildOfOne implements One {}
@@ -199,6 +223,8 @@ public class OverridesTest {
     abstract static class AbstractChildOfOneAndTwo implements One, Two {}
 
     abstract static class AbstractChildOfParentAndOneAndTwo extends Parent implements One, Two {}
+
+    interface ExtendingOneAndTwo extends One, Two {}
   }
 
   static class MoreTypesForInheritance {
diff --git a/debian/changelog b/debian/changelog
index 2e13dcb..5eff5e3 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+google-auto-common-java (1.2.1-1) UNRELEASED; urgency=low
+
+  * New upstream release.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 01 May 2023 01:11:28 -0000
+
 google-auto-common-java (1.1.2-1) unstable; urgency=high
 
   * New upstream release (Closes: #1021630)
diff --git a/debian/patches/add-checkerframework-dependency.patch b/debian/patches/add-checkerframework-dependency.patch
index e8662c7..d21c729 100644
--- a/debian/patches/add-checkerframework-dependency.patch
+++ b/debian/patches/add-checkerframework-dependency.patch
@@ -3,8 +3,10 @@ Author: Olek Wojnar <olek@debian.org>
 Forwarded: not-needed
 Last-Update: 2022-12-21
 
---- a/common/pom.xml
-+++ b/common/pom.xml
+Index: google-auto-common-java.git/common/pom.xml
+===================================================================
+--- google-auto-common-java.git.orig/common/pom.xml
++++ google-auto-common-java.git/common/pom.xml
 @@ -78,6 +78,10 @@
        <version>1.13.0</version>
        <optional>true</optional>
diff --git a/debian/patches/fix-base-pom.patch b/debian/patches/fix-base-pom.patch
index 5a2159f..85d8200 100644
--- a/debian/patches/fix-base-pom.patch
+++ b/debian/patches/fix-base-pom.patch
@@ -3,7 +3,9 @@ Author: Olek Wojnar <olek@debian.org>
 Forwarded: not-needed
 Last-Update: 2022-12-20
 
---- a/build-pom.xml
+Index: google-auto-common-java.git/build-pom.xml
+===================================================================
+--- google-auto-common-java.git.orig/build-pom.xml
 +++ /dev/null
 @@ -1,26 +0,0 @@
 -<!-- A pure convenience for local builds and travis-ci. -->
@@ -32,8 +34,10 @@ Last-Update: 2022-12-20
 -    </snapshotRepository>
 -  </distributionManagement>
 -</project>
+Index: google-auto-common-java.git/pom.xml
+===================================================================
 --- /dev/null
-+++ b/pom.xml
++++ google-auto-common-java.git/pom.xml
 @@ -0,0 +1,23 @@
 +<!-- A pure convenience for local builds and travis-ci. -->
 +<project>
diff --git a/debian/patches/verbose-build.patch b/debian/patches/verbose-build.patch
index 52ee335..521e516 100644
--- a/debian/patches/verbose-build.patch
+++ b/debian/patches/verbose-build.patch
@@ -3,8 +3,10 @@ Author: Olek Wojnar <olek@debian.org>
 Forwarded: not-needed
 Last-Update: 2022-12-20
 
---- a/common/pom.xml
-+++ b/common/pom.xml
+Index: google-auto-common-java.git/common/pom.xml
+===================================================================
+--- google-auto-common-java.git.orig/common/pom.xml
++++ google-auto-common-java.git/common/pom.xml
 @@ -121,6 +121,7 @@
            <source>${java.version}</source>
            <target>${java.version}</target>
diff --git a/factory/pom.xml b/factory/pom.xml
index 62f9df3..b7ad3c9 100644
--- a/factory/pom.xml
+++ b/factory/pom.xml
@@ -19,12 +19,6 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
-  <parent>
-    <groupId>org.sonatype.oss</groupId>
-    <artifactId>oss-parent</artifactId>
-    <version>7</version>
-  </parent>
-
   <groupId>com.google.auto.factory</groupId>
   <artifactId>auto-factory</artifactId>
   <version>HEAD-SNAPSHOT</version>
@@ -36,10 +30,10 @@
 
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
-    <auto-service.version>1.0</auto-service.version>
+    <auto-service.version>1.0.1</auto-service.version>
     <auto-value.version>1.8.2</auto-value.version>
     <java.version>1.8</java.version>
-    <guava.version>30.1.1-jre</guava.version>
+    <guava.version>31.0.1-jre</guava.version>
     <truth.version>1.1.3</truth.version>
   </properties>
 
@@ -71,7 +65,7 @@
     <dependency>
       <groupId>com.google.auto</groupId>
       <artifactId>auto-common</artifactId>
-      <version>1.1</version>
+      <version>1.2</version>
     </dependency>
     <dependency>
       <groupId>com.google.auto.value</groupId>
@@ -170,7 +164,7 @@
           <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-java</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.0</version>
           </dependency>
         </dependencies>
       </plugin>
diff --git a/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java b/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java
index b7f9c3e..8d6027d 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/FactoryWriter.java
@@ -29,6 +29,7 @@ import static javax.lang.model.element.Modifier.STATIC;
 
 import com.google.auto.common.AnnotationMirrors;
 import com.google.auto.common.AnnotationValues;
+import com.google.auto.common.MoreTypes;
 import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.ImmutableSetMultimap;
@@ -59,6 +60,7 @@ import javax.lang.model.SourceVersion;
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.Element;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.DeclaredType;
 import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import javax.lang.model.type.TypeVariable;
@@ -338,9 +340,28 @@ final class FactoryWriter {
     for (ProviderField provider : descriptor.providers().values()) {
       typeVariables.addAll(getReferencedTypeParameterNames(provider.key().type().get()));
     }
+    // If a parent type has a type parameter, like FooFactory<T>, then the generated factory needs
+    // to have the same parameter, like FooImplFactory<T> extends FooFactory<T>. This is a little
+    // approximate, at least in the case where there is more than one parent type that has a type
+    // parameter. But that should be pretty rare, so let's keep it simple for now.
+    typeVariables.addAll(typeVariablesFrom(descriptor.extendingType()));
+    for (TypeMirror implementing : descriptor.implementingTypes()) {
+      typeVariables.addAll(typeVariablesFrom(implementing));
+    }
     return typeVariables.build();
   }
 
+  private static List<TypeVariableName> typeVariablesFrom(TypeMirror type) {
+    if (type.getKind().equals(TypeKind.DECLARED)) {
+      DeclaredType declaredType = MoreTypes.asDeclared(type);
+      return declaredType.getTypeArguments().stream()
+          .filter(t -> t.getKind().equals(TypeKind.TYPEVAR))
+          .map(t -> TypeVariableName.get(MoreTypes.asTypeVariable(t)))
+          .collect(toList());
+    }
+    return ImmutableList.of();
+  }
+
   private static ImmutableSet<TypeVariableName> getMethodTypeVariables(
       FactoryMethodDescriptor methodDescriptor,
       ImmutableSet<TypeVariableName> factoryTypeVariables) {
diff --git a/factory/src/main/java/com/google/auto/factory/processor/Key.java b/factory/src/main/java/com/google/auto/factory/processor/Key.java
index 728149e..6dc7644 100644
--- a/factory/src/main/java/com/google/auto/factory/processor/Key.java
+++ b/factory/src/main/java/com/google/auto/factory/processor/Key.java
@@ -97,7 +97,7 @@ abstract class Key {
   public final String toString() {
     String typeQualifiedName = MoreTypes.asTypeElement(type().get()).toString();
     return qualifier().isPresent()
-        ? qualifier().get() + "/" + typeQualifiedName
+        ? AnnotationMirrors.toString(qualifier().get()) + "/" + typeQualifiedName
         : typeQualifiedName;
   }
 }
diff --git a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
index 0df4c9c..2ab0fe9 100644
--- a/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
+++ b/factory/src/test/java/com/google/auto/factory/processor/AutoFactoryProcessorTest.java
@@ -508,6 +508,22 @@ public class AutoFactoryProcessorTest {
         .hasSourceEquivalentTo(loadExpectedFile("expected/DefaultPackageFactory.java"));
   }
 
+  @Test
+  public void generics() {
+    JavaFileObject file = JavaFileObjects.forResource("good/Generics.java");
+    Compilation compilation = javac.compile(file);
+    assertThat(compilation).succeededWithoutWarnings();
+    assertThat(compilation)
+        .generatedSourceFile("tests.Generics_FooImplFactory")
+        .hasSourceEquivalentTo(loadExpectedFile("expected/Generics_FooImplFactory.java"));
+    assertThat(compilation)
+        .generatedSourceFile("tests.Generics_ExplicitFooImplFactory")
+        .hasSourceEquivalentTo(loadExpectedFile("expected/Generics_ExplicitFooImplFactory.java"));
+    assertThat(compilation)
+        .generatedSourceFile("tests.Generics_FooImplWithClassFactory")
+        .hasSourceEquivalentTo(loadExpectedFile("expected/Generics_FooImplWithClassFactory.java"));
+  }
+
   private JavaFileObject loadExpectedFile(String resourceName) {
     if (isJavaxAnnotationProcessingGeneratedAvailable()) {
       return JavaFileObjects.forResource(resourceName);
diff --git a/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java b/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java
new file mode 100644
index 0000000..00c6d92
--- /dev/null
+++ b/factory/src/test/resources/expected/Generics_ExplicitFooImplFactory.java
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests;
+
+import javax.annotation.processing.Generated;
+import javax.inject.Inject;
+import javax.inject.Provider;
+
+@Generated(
+    value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+    comments = "https://github.com/google/auto/tree/master/factory"
+    )
+final class Generics_ExplicitFooImplFactory<M extends Generics.Bar>
+    implements Generics.FooFactory<M> {
+  private final Provider<M> unusedProvider;
+
+  @Inject
+  Generics_ExplicitFooImplFactory(Provider<M> unusedProvider) {
+    this.unusedProvider = checkNotNull(unusedProvider, 1);
+  }
+
+  @Override
+  public Generics.ExplicitFooImpl<M> create() {
+    return new Generics.ExplicitFooImpl<M>(checkNotNull(unusedProvider.get(), 1));
+  }
+
+  private static <T> T checkNotNull(T reference, int argumentIndex) {
+    if (reference == null) {
+      throw new NullPointerException(
+          "@AutoFactory method argument is null but is not marked @Nullable. Argument index: "
+              + argumentIndex);
+    }
+    return reference;
+  }
+}
diff --git a/factory/src/test/resources/expected/Generics_FooImplFactory.java b/factory/src/test/resources/expected/Generics_FooImplFactory.java
new file mode 100644
index 0000000..2fb560a
--- /dev/null
+++ b/factory/src/test/resources/expected/Generics_FooImplFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests;
+
+import javax.annotation.processing.Generated;
+import javax.inject.Inject;
+
+@Generated(
+    value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+    comments = "https://github.com/google/auto/tree/master/factory"
+    )
+final class Generics_FooImplFactory<M extends Generics.Bar> implements Generics.FooFactory<M> {
+  @Inject
+  Generics_FooImplFactory() {
+  }
+
+  @Override
+  public Generics.FooImpl<M> create() {
+    return new Generics.FooImpl<M>();
+  }
+}
diff --git a/factory/src/test/resources/expected/Generics_FooImplWithClassFactory.java b/factory/src/test/resources/expected/Generics_FooImplWithClassFactory.java
new file mode 100644
index 0000000..b338454
--- /dev/null
+++ b/factory/src/test/resources/expected/Generics_FooImplWithClassFactory.java
@@ -0,0 +1,34 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests;
+
+import javax.annotation.processing.Generated;
+import javax.inject.Inject;
+
+@Generated(
+    value = "com.google.auto.factory.processor.AutoFactoryProcessor",
+    comments = "https://github.com/google/auto/tree/master/factory"
+    )
+final class Generics_FooImplWithClassFactory<M extends Generics.Bar> extends Generics.FooFactoryClass<M> {
+  @Inject
+  Generics_FooImplWithClassFactory() {
+  }
+
+  @Override
+  public Generics.FooImplWithClass<M> create() {
+    return new Generics.FooImplWithClass<M>();
+  }
+}
diff --git a/factory/src/test/resources/good/Generics.java b/factory/src/test/resources/good/Generics.java
new file mode 100644
index 0000000..638302f
--- /dev/null
+++ b/factory/src/test/resources/good/Generics.java
@@ -0,0 +1,50 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package tests;
+
+import com.google.auto.factory.AutoFactory;
+import com.google.auto.factory.Provided;
+
+class Generics {
+  interface Bar {}
+
+  interface Foo<M extends Bar> {}
+
+  interface FooFactory<M extends Bar> {
+    Foo<M> create();
+  }
+
+  // The generated FooImplFactory should also have an <M extends Bar> type parameter, so we can
+  // have FooImplFactory<M extends Bar> implements FooFactory<M>.
+  @AutoFactory(implementing = FooFactory.class)
+  static final class FooImpl<M extends Bar> implements Foo<M> {
+    FooImpl() {}
+  }
+
+  // The generated ExplicitFooImplFactory should have an <M extends Bar> type parameter, which
+  // serves both for FooFactory<M> and for Provider<M> in the constructor.
+  @AutoFactory(implementing = FooFactory.class)
+  static final class ExplicitFooImpl<M extends Bar> implements Foo<M> {
+    ExplicitFooImpl(@Provided M unused) {}
+  }
+
+  abstract static class FooFactoryClass<M extends Bar> {
+    abstract Foo<M> create();
+  }
+
+  @AutoFactory(extending = FooFactoryClass.class)
+  static final class FooImplWithClass<M extends Bar> implements Foo<M> {}
+}
diff --git a/service/pom.xml b/service/pom.xml
index e29bdc3..f306885 100644
--- a/service/pom.xml
+++ b/service/pom.xml
@@ -37,7 +37,7 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <java.version>1.8</java.version>
-    <guava.version>30.1.1-jre</guava.version>
+    <guava.version>31.0.1-jre</guava.version>
     <truth.version>1.1.3</truth.version>
   </properties>
 
@@ -123,7 +123,7 @@
             <dependency>
               <groupId>org.codehaus.plexus</groupId>
               <artifactId>plexus-java</artifactId>
-              <version>1.0.7</version>
+              <version>1.1.0</version>
             </dependency>
           </dependencies>
         </plugin>
diff --git a/service/processor/pom.xml b/service/processor/pom.xml
index 262493a..76fd848 100644
--- a/service/processor/pom.xml
+++ b/service/processor/pom.xml
@@ -49,7 +49,7 @@
     <dependency>
       <groupId>com.google.auto</groupId>
       <artifactId>auto-common</artifactId>
-      <version>1.1</version>
+      <version>1.2</version>
     </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
diff --git a/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java b/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java
index f12299a..85a24cb 100644
--- a/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java
+++ b/service/processor/src/main/java/com/google/auto/service/processor/AutoServiceProcessor.java
@@ -25,12 +25,15 @@ import com.google.auto.common.MoreTypes;
 import com.google.auto.service.AutoService;
 import com.google.common.annotations.VisibleForTesting;
 import com.google.common.collect.HashMultimap;
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Multimap;
 import com.google.common.collect.Sets;
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
@@ -68,6 +71,8 @@ public class AutoServiceProcessor extends AbstractProcessor {
   @VisibleForTesting
   static final String MISSING_SERVICES_ERROR = "No service interfaces provided for element!";
 
+  private final List<String> exceptionStacks = Collections.synchronizedList(new ArrayList<>());
+
   /**
    * Maps the class names of service provider interfaces to the
    * class names of the concrete classes which implement them.
@@ -109,11 +114,17 @@ public class AutoServiceProcessor extends AbstractProcessor {
       processImpl(annotations, roundEnv);
     } catch (RuntimeException e) {
       // We don't allow exceptions of any kind to propagate to the compiler
-      fatalError(getStackTraceAsString(e));
+      String trace = getStackTraceAsString(e);
+      exceptionStacks.add(trace);
+      fatalError(trace);
     }
     return false;
   }
 
+  ImmutableList<String> exceptionStacks() {
+    return ImmutableList.copyOf(exceptionStacks);
+  }
+
   private void processImpl(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
     if (roundEnv.processingOver()) {
       generateConfigFiles();
@@ -291,7 +302,7 @@ public class AutoServiceProcessor extends AbstractProcessor {
   private ImmutableSet<DeclaredType> getValueFieldOfClasses(AnnotationMirror annotationMirror) {
     return getAnnotationValue(annotationMirror, "value")
         .accept(
-            new SimpleAnnotationValueVisitor8<ImmutableSet<DeclaredType>, Void>() {
+            new SimpleAnnotationValueVisitor8<ImmutableSet<DeclaredType>, Void>(ImmutableSet.of()) {
               @Override
               public ImmutableSet<DeclaredType> visitType(TypeMirror typeMirror, Void v) {
                 // TODO(ronshapiro): class literals may not always be declared types, i.e.
diff --git a/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java b/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java
index 3561568..7a176dd 100644
--- a/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java
+++ b/service/processor/src/test/java/com/google/auto/service/processor/AutoServiceProcessorTest.java
@@ -17,6 +17,7 @@ package com.google.auto.service.processor;
 
 import static com.google.auto.service.processor.AutoServiceProcessor.MISSING_SERVICES_ERROR;
 import static com.google.testing.compile.CompilationSubject.assertThat;
+import static com.google.common.truth.Truth.assertThat;
 
 import com.google.common.io.Resources;
 import com.google.testing.compile.Compilation;
@@ -144,4 +145,18 @@ public class AutoServiceProcessorTest {
         .contentsAsUtf8String()
         .isEqualTo("test.EnclosingGeneric$GenericServiceProvider\n");
   }
+
+  @Test
+  public void missing() {
+    AutoServiceProcessor processor = new AutoServiceProcessor();
+    Compilation compilation =
+        Compiler.javac()
+            .withProcessors(processor)
+            .withOptions("-Averify=true")
+            .compile(
+                JavaFileObjects.forResource(
+                    "test/GenericServiceProviderWithMissingServiceClass.java"));
+    assertThat(compilation).failed();
+    assertThat(processor.exceptionStacks()).isEmpty();
+  }
 }
diff --git a/service/processor/src/test/resources/test/GenericServiceProviderWithMissingServiceClass.java b/service/processor/src/test/resources/test/GenericServiceProviderWithMissingServiceClass.java
new file mode 100644
index 0000000..3ca3445
--- /dev/null
+++ b/service/processor/src/test/resources/test/GenericServiceProviderWithMissingServiceClass.java
@@ -0,0 +1,25 @@
+/*
+ * Copyright 2021 Google LLC
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package test;
+
+import com.google.auto.service.AutoService;
+
+/**
+ * A service that references a missing class. This is useful for testing that the processor behaves
+ * correctly.
+ */
+@AutoService(MissingServiceClass.class)
+public class GenericServiceProviderWithMissingServiceClass<T> implements MissingServiceClass<T> {}
diff --git a/value/pom.xml b/value/pom.xml
index 70ad3ac..bce8e5f 100644
--- a/value/pom.xml
+++ b/value/pom.xml
@@ -18,12 +18,6 @@
   xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
   <modelVersion>4.0.0</modelVersion>
 
-  <parent>
-    <groupId>org.sonatype.oss</groupId>
-    <artifactId>oss-parent</artifactId>
-    <version>7</version>
-  </parent>
-
   <groupId>com.google.auto.value</groupId>
   <artifactId>auto-value-parent</artifactId>
   <version>HEAD-SNAPSHOT</version>
@@ -37,7 +31,7 @@
   <properties>
     <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
     <java.version>1.8</java.version>
-    <guava.version>30.1.1-jre</guava.version>
+    <guava.version>31.0.1-jre</guava.version>
     <truth.version>1.1.3</truth.version>
   </properties>
 
@@ -150,7 +144,7 @@
             <dependency>
               <groupId>org.codehaus.plexus</groupId>
               <artifactId>plexus-java</artifactId>
-              <version>1.0.7</version>
+              <version>1.1.0</version>
             </dependency>
           </dependencies>
         </plugin>
diff --git a/value/processor/pom.xml b/value/processor/pom.xml
index dd2a5d9..fdfa60c 100644
--- a/value/processor/pom.xml
+++ b/value/processor/pom.xml
@@ -41,15 +41,15 @@
   </scm>
 
   <properties>
-    <auto-service.version>1.0</auto-service.version>
-    <errorprone.version>2.8.0</errorprone.version>
+    <auto-service.version>1.0.1</auto-service.version>
+    <errorprone.version>2.10.0</errorprone.version>
   </properties>
 
   <dependencies>
     <dependency>
       <groupId>com.google.auto</groupId>
       <artifactId>auto-common</artifactId>
-      <version>1.1</version>
+      <version>1.2</version>
     </dependency>
     <dependency>
       <groupId>com.google.auto.service</groupId>
@@ -125,7 +125,7 @@
     <dependency>
        <groupId>org.mockito</groupId>
        <artifactId>mockito-core</artifactId>
-       <version>3.11.2</version>
+       <version>4.0.0</version>
        <scope>test</scope>
      </dependency>
   </dependencies>
diff --git a/value/src/it/functional/pom.xml b/value/src/it/functional/pom.xml
index 0dc89c2..48dda7c 100644
--- a/value/src/it/functional/pom.xml
+++ b/value/src/it/functional/pom.xml
@@ -32,7 +32,7 @@
   <version>HEAD-SNAPSHOT</version>
   <name>Auto-Value Functional Integration Test</name>
   <properties>
-    <kotlin.version>1.5.21</kotlin.version>
+    <kotlin.version>1.5.31</kotlin.version>
     <exclude.tests>this-matches-nothing</exclude.tests>
   </properties>
   <dependencies>
@@ -49,7 +49,7 @@
     <dependency>
       <groupId>com.google.auto.service</groupId>
       <artifactId>auto-service</artifactId>
-      <version>1.0</version>
+      <version>1.0.1</version>
     </dependency>
     <dependency>
       <groupId>com.google.guava</groupId>
@@ -93,13 +93,13 @@
     <dependency>
       <groupId>dev.gradleplugins</groupId>
       <artifactId>gradle-test-kit</artifactId>
-      <version>6.8.3</version>
+      <version>7.2</version>
       <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
-      <version>3.11.2</version>
+      <version>4.0.0</version>
       <scope>test</scope>
     </dependency>
     <dependency>
@@ -166,7 +166,7 @@
           <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-java</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.0</version>
           </dependency>
         </dependencies>
         <configuration>
@@ -221,7 +221,7 @@
               <dependency>
                 <groupId>org.codehaus.plexus</groupId>
                 <artifactId>plexus-java</artifactId>
-                <version>1.0.7</version>
+                <version>1.1.0</version>
               </dependency>
             </dependencies>
             <configuration>
diff --git a/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java b/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java
index 952edaa..dba8199 100644
--- a/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java
+++ b/value/src/it/functional/src/test/java/com/google/auto/value/AutoBuilderTest.java
@@ -149,6 +149,12 @@ public final class AutoBuilderTest {
     return new AutoAnnotation_AutoBuilderTest_myAnnotation(value, truthiness);
   }
 
+  // This method has parameters for all the annotation elements.
+  @AutoAnnotation
+  static MyAnnotation myAnnotationAll(String value, int id, Truthiness truthiness) {
+    return new AutoAnnotation_AutoBuilderTest_myAnnotationAll(value, id, truthiness);
+  }
+
   @AutoBuilder(callMethod = "myAnnotation")
   interface MyAnnotationBuilder {
     MyAnnotationBuilder value(String x);
@@ -159,12 +165,28 @@ public final class AutoBuilderTest {
   }
 
   static MyAnnotationBuilder myAnnotationBuilder() {
-    return new AutoBuilder_AutoBuilderTest_MyAnnotationBuilder()
-        .truthiness(MyAnnotation.DEFAULT_TRUTHINESS);
+    return new AutoBuilder_AutoBuilderTest_MyAnnotationBuilder();
+  }
+
+  @AutoBuilder(callMethod = "myAnnotationAll")
+  interface MyAnnotationAllBuilder {
+    MyAnnotationAllBuilder value(String x);
+
+    MyAnnotationAllBuilder id(int x);
+
+    MyAnnotationAllBuilder truthiness(Truthiness x);
+
+    MyAnnotation build();
+  }
+
+  static MyAnnotationAllBuilder myAnnotationAllBuilder() {
+    return new AutoBuilder_AutoBuilderTest_MyAnnotationAllBuilder();
   }
 
   @Test
   public void simpleAutoAnnotation() {
+    // We haven't supplied a value for `truthiness`, so AutoBuilder should use the default one in
+    // the annotation.
     MyAnnotation annotation1 = myAnnotationBuilder().value("foo").build();
     assertThat(annotation1.value()).isEqualTo("foo");
     assertThat(annotation1.id()).isEqualTo(MyAnnotation.DEFAULT_ID);
@@ -174,6 +196,15 @@ public final class AutoBuilderTest {
     assertThat(annotation2.value()).isEqualTo("bar");
     assertThat(annotation2.id()).isEqualTo(MyAnnotation.DEFAULT_ID);
     assertThat(annotation2.truthiness()).isEqualTo(Truthiness.TRUTHY);
+
+    MyAnnotation annotation3 = myAnnotationAllBuilder().value("foo").build();
+    MyAnnotation annotation4 =
+        myAnnotationAllBuilder()
+            .value("foo")
+            .id(MyAnnotation.DEFAULT_ID)
+            .truthiness(MyAnnotation.DEFAULT_TRUTHINESS)
+            .build();
+    assertThat(annotation3).isEqualTo(annotation4);
   }
 
   static class Overload {
diff --git a/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java b/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java
index 3a7e7bc..fd87b3e 100644
--- a/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java
+++ b/value/src/it/functional/src/test/java/com/google/auto/value/AutoValueTest.java
@@ -3623,4 +3623,48 @@ public class AutoValueTest {
     } catch (IllegalStateException expected) {
     }
   }
+
+  @AutoValue
+  public abstract static class Stepped {
+    public abstract String one();
+
+    public abstract int two();
+
+    public abstract double three();
+
+    public interface StepOne<T> {
+      StepTwo setOne(T x);
+    }
+
+    public interface StepTwo {
+      StepThree setTwo(int x);
+    }
+
+    public interface StepThree {
+      Stepped setThreeAndBuild(double x);
+    }
+
+    public static StepOne<String> builder() {
+      return new AutoValue_AutoValueTest_Stepped.Builder();
+    }
+
+    @AutoValue.Builder
+    abstract static class Builder implements StepOne<String>, StepTwo, StepThree {
+      abstract Builder setThree(double x);
+      abstract Stepped build();
+
+      @Override
+      public Stepped setThreeAndBuild(double x) {
+        return setThree(x).build();
+      }
+    }
+  }
+
+  @Test
+  public void stepBuilder() {
+    Stepped stepped = Stepped.builder().setOne("one").setTwo(2).setThreeAndBuild(3.0);
+    assertThat(stepped.one()).isEqualTo("one");
+    assertThat(stepped.two()).isEqualTo(2);
+    assertThat(stepped.three()).isEqualTo(3.0);
+  }
 }
diff --git a/value/src/it/gwtserializer/pom.xml b/value/src/it/gwtserializer/pom.xml
index 407563e..88bf677 100644
--- a/value/src/it/gwtserializer/pom.xml
+++ b/value/src/it/gwtserializer/pom.xml
@@ -99,7 +99,7 @@
           <dependency>
             <groupId>org.codehaus.plexus</groupId>
             <artifactId>plexus-java</artifactId>
-            <version>1.0.7</version>
+            <version>1.1.0</version>
           </dependency>
         </dependencies>
         <configuration>
diff --git a/value/src/main/java/com/google/auto/value/AutoAnnotation.java b/value/src/main/java/com/google/auto/value/AutoAnnotation.java
index d36d8e2..c6fab24 100644
--- a/value/src/main/java/com/google/auto/value/AutoAnnotation.java
+++ b/value/src/main/java/com/google/auto/value/AutoAnnotation.java
@@ -71,6 +71,39 @@ import java.lang.reflect.AnnotatedElement;
  * parameter corresponding to an array-valued annotation member, and the implementation of each such
  * member will also return a clone of the array.
  *
+ * <p>If your annotation has many elements, you may consider using {@code @AutoBuilder} to make it
+ * easier to construct instances. In that case, {@code default} values from the annotation will
+ * become default values for the parameters of the {@code @AutoAnnotation} method. For example:
+ *
+ * <pre>
+ * class Example {
+ *   {@code @interface} MyAnnotation {
+ *     String name() default "foo";
+ *     int number() default 23;
+ *   }
+ *
+ *   {@code @AutoAnnotation}
+ *   static MyAnnotation myAnnotation(String value) {
+ *     return new AutoAnnotation_Example_myAnnotation(value);
+ *   }
+ *
+ *   {@code @AutoBuilder(callMethod = "myAnnotation")}
+ *   interface MyAnnotationBuilder {
+ *     MyAnnotationBuilder name(String name);
+ *     MyAnnotationBuilder number(int number);
+ *     MyAnnotation build();
+ *   }
+ *
+ *   static MyAnnotationBuilder myAnnotationBuilder() {
+ *     return new AutoBuilder_Example_MyAnnotationBuilder();
+ *   }
+ * }
+ * </pre>
+ *
+ * Here, {@code myAnnotationBuilder().build()} is the same as {@code
+ * myAnnotationBuilder().name("foo").number(23).build()} because those are the defaults in the
+ * annotation definition.
+ *
  * @author emcmanus@google.com (Éamonn McManus)
  */
 @Target(ElementType.METHOD)
diff --git a/value/src/main/java/com/google/auto/value/processor/AnnotationOutput.java b/value/src/main/java/com/google/auto/value/processor/AnnotationOutput.java
index ed986ab..ed6abaa 100644
--- a/value/src/main/java/com/google/auto/value/processor/AnnotationOutput.java
+++ b/value/src/main/java/com/google/auto/value/processor/AnnotationOutput.java
@@ -15,6 +15,8 @@
  */
 package com.google.auto.value.processor;
 
+import com.google.auto.common.MoreTypes;
+import com.google.auto.value.processor.MissingTypes.MissingTypeException;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.Iterables;
 import java.util.List;
@@ -24,8 +26,10 @@ import javax.annotation.processing.ProcessingEnvironment;
 import javax.lang.model.element.AnnotationMirror;
 import javax.lang.model.element.AnnotationValue;
 import javax.lang.model.element.Element;
+import javax.lang.model.element.ElementKind;
 import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import javax.lang.model.util.SimpleAnnotationValueVisitor8;
 import javax.tools.Diagnostic;
@@ -130,13 +134,13 @@ final class AnnotationOutput {
   private static class InitializerSourceFormVisitor extends SourceFormVisitor {
     private final ProcessingEnvironment processingEnv;
     private final String memberName;
-    private final Element context;
+    private final Element errorContext;
 
     InitializerSourceFormVisitor(
-        ProcessingEnvironment processingEnv, String memberName, Element context) {
+        ProcessingEnvironment processingEnv, String memberName, Element errorContext) {
       this.processingEnv = processingEnv;
       this.memberName = memberName;
-      this.context = context;
+      this.errorContext = errorContext;
     }
 
     @Override
@@ -148,7 +152,7 @@ final class AnnotationOutput {
               "@AutoAnnotation cannot yet supply a default value for annotation-valued member '"
                   + memberName
                   + "'",
-              context);
+              errorContext);
       sb.append("null");
       return null;
     }
@@ -209,9 +213,9 @@ final class AnnotationOutput {
       AnnotationValue annotationValue,
       ProcessingEnvironment processingEnv,
       String memberName,
-      Element context) {
+      Element errorContext) {
     SourceFormVisitor visitor =
-        new InitializerSourceFormVisitor(processingEnv, memberName, context);
+        new InitializerSourceFormVisitor(processingEnv, memberName, errorContext);
     StringBuilder sb = new StringBuilder();
     visitor.visit(annotationValue, sb);
     return sb.toString();
@@ -222,11 +226,59 @@ final class AnnotationOutput {
    * Java source file to reproduce the annotation in source form.
    */
   static String sourceFormForAnnotation(AnnotationMirror annotationMirror) {
+    // If a value in the annotation is a reference to a class constant and that class constant is
+    // undefined, javac unhelpfully converts it into a string "<error>" and visits that instead. We
+    // want to catch this case and defer processing to allow the class to be defined by another
+    // annotation processor. So we look for annotation elements whose type is Class but whose
+    // reported value is a string. Unfortunately we can't extract the ErrorType corresponding to the
+    // missing class portably. With javac, the AttributeValue is a
+    // com.sun.tools.javac.code.Attribute.UnresolvedClass, which has a public field classType that
+    // is the ErrorType we need, but obviously that's nonportable and fragile.
+    validateClassValues(annotationMirror);
     StringBuilder sb = new StringBuilder();
     new AnnotationSourceFormVisitor().visitAnnotation(annotationMirror, sb);
     return sb.toString();
   }
 
+  /**
+   * Throws an exception if this annotation contains a value for a Class element that is not
+   * actually a type. The assumption is that the value is the string {@code "<error>"} which javac
+   * presents when a Class value is an undefined type.
+   */
+  private static void validateClassValues(AnnotationMirror annotationMirror) {
+    // A class literal can appear in three places:
+    // * for an element of type Class, for example @SomeAnnotation(Foo.class);
+    // * for an element of type Class[], for example @SomeAnnotation({Foo.class, Bar.class});
+    // * inside a nested annotation, for example @SomeAnnotation(@Nested(Foo.class)).
+    // These three possibilities are the three branches of the if/else chain below.
+    annotationMirror
+        .getElementValues()
+        .forEach(
+            (method, value) -> {
+              TypeMirror type = method.getReturnType();
+              if (isJavaLangClass(type) && !(value.getValue() instanceof TypeMirror)) {
+                throw new MissingTypeException(null);
+              } else if (type.getKind().equals(TypeKind.ARRAY)
+                  && isJavaLangClass(MoreTypes.asArray(type).getComponentType())
+                  && value.getValue() instanceof List<?>) {
+                @SuppressWarnings("unchecked") // a List can only be a List<AnnotationValue> here
+                List<AnnotationValue> values = (List<AnnotationValue>) value.getValue();
+                if (values.stream().anyMatch(av -> !(av.getValue() instanceof TypeMirror))) {
+                  throw new MissingTypeException(null);
+                }
+              } else if (type.getKind().equals(TypeKind.DECLARED)
+                  && MoreTypes.asElement(type).getKind().equals(ElementKind.ANNOTATION_TYPE)
+                  && value.getValue() instanceof AnnotationMirror) {
+                validateClassValues((AnnotationMirror) value.getValue());
+              }
+            });
+  }
+
+  private static boolean isJavaLangClass(TypeMirror type) {
+    return type.getKind().equals(TypeKind.DECLARED)
+        && MoreTypes.asTypeElement(type).getQualifiedName().contentEquals("java.lang.Class");
+  }
+
   private static StringBuilder appendQuoted(StringBuilder sb, String s) {
     sb.append('"');
     for (int i = 0; i < s.length(); i++) {
diff --git a/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java
index 3acf933..cc0e62e 100644
--- a/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java
+++ b/value/src/main/java/com/google/auto/value/processor/AutoAnnotationProcessor.java
@@ -287,7 +287,7 @@ public class AutoAnnotationProcessor extends AbstractProcessor {
   private String generatedClassName(ExecutableElement method) {
     TypeElement type = MoreElements.asType(method.getEnclosingElement());
     String name = type.getSimpleName().toString();
-    while (type.getEnclosingElement() instanceof TypeElement) {
+    while (MoreElements.isType(type.getEnclosingElement())) {
       type = MoreElements.asType(type.getEnclosingElement());
       name = type.getSimpleName() + "_" + name;
     }
diff --git a/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java
index b6a578f..53fe836 100644
--- a/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java
+++ b/value/src/main/java/com/google/auto/value/processor/AutoBuilderProcessor.java
@@ -20,6 +20,7 @@ import static com.google.auto.common.MoreElements.getPackage;
 import static com.google.auto.common.MoreStreams.toImmutableList;
 import static com.google.auto.common.MoreStreams.toImmutableSet;
 import static com.google.auto.value.processor.AutoValueProcessor.OMIT_IDENTIFIERS_OPTION;
+import static com.google.auto.value.processor.ClassNames.AUTO_ANNOTATION_NAME;
 import static com.google.auto.value.processor.ClassNames.AUTO_BUILDER_NAME;
 import static java.util.stream.Collectors.joining;
 import static java.util.stream.Collectors.toCollection;
@@ -38,6 +39,7 @@ import com.google.auto.value.processor.MissingTypes.MissingTypeException;
 import com.google.common.base.Ascii;
 import com.google.common.base.VerifyException;
 import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.collect.Maps;
 import java.lang.reflect.Field;
@@ -60,6 +62,7 @@ import javax.lang.model.element.Modifier;
 import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.TypeElement;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import net.ltgt.gradle.incap.IncrementalAnnotationProcessor;
 import net.ltgt.gradle.incap.IncrementalAnnotationProcessorType;
@@ -134,7 +137,7 @@ public class AutoBuilderProcessor extends AutoValueishProcessor {
     Map<String, String> propertyToGetterName =
         Maps.transformValues(classifier.builderGetters(), PropertyGetter::getName);
     AutoBuilderTemplateVars vars = new AutoBuilderTemplateVars();
-    vars.props = propertySet(executable, propertyToGetterName);
+    vars.props = propertySet(autoBuilderType, executable, propertyToGetterName);
     builder.defineVars(vars, classifier);
     vars.identifiers = !processingEnv.getOptions().containsKey(OMIT_IDENTIFIERS_OPTION);
     String generatedClassName = generatedClassName(autoBuilderType, "AutoBuilder_");
@@ -152,7 +155,15 @@ public class AutoBuilderProcessor extends AutoValueishProcessor {
   }
 
   private ImmutableSet<Property> propertySet(
-      ExecutableElement executable, Map<String, String> propertyToGetterName) {
+      TypeElement autoBuilderType,
+      ExecutableElement executable,
+      Map<String, String> propertyToGetterName) {
+    boolean autoAnnotation =
+        MoreElements.getAnnotationMirror(executable, AUTO_ANNOTATION_NAME).isPresent();
+    ImmutableMap<String, String> builderInitializers =
+        autoAnnotation
+            ? autoAnnotationInitializers(autoBuilderType, executable)
+            : ImmutableMap.of();
     // Fix any parameter names that are reserved words in Java. Java source code can't have
     // such parameter names, but Kotlin code might, for example.
     Map<VariableElement, String> identifiers =
@@ -161,18 +172,58 @@ public class AutoBuilderProcessor extends AutoValueishProcessor {
     fixReservedIdentifiers(identifiers);
     return executable.getParameters().stream()
         .map(
-            v ->
-                newProperty(
-                    v, identifiers.get(v), propertyToGetterName.get(v.getSimpleName().toString())))
+            v -> {
+              String name = v.getSimpleName().toString();
+              return newProperty(
+                  v,
+                  identifiers.get(v),
+                  propertyToGetterName.get(name),
+                  Optional.ofNullable(builderInitializers.get(name)));
+            })
         .collect(toImmutableSet());
   }
 
-  private Property newProperty(VariableElement var, String identifier, String getterName) {
+  private Property newProperty(
+      VariableElement var,
+      String identifier,
+      String getterName,
+      Optional<String> builderInitializer) {
     String name = var.getSimpleName().toString();
     TypeMirror type = var.asType();
     Optional<String> nullableAnnotation = nullableAnnotationFor(var, var.asType());
     return new Property(
-        name, identifier, TypeEncoder.encode(type), type, nullableAnnotation, getterName);
+        name,
+        identifier,
+        TypeEncoder.encode(type),
+        type,
+        nullableAnnotation,
+        getterName,
+        builderInitializer);
+  }
+
+  private ImmutableMap<String, String> autoAnnotationInitializers(
+      TypeElement autoBuilderType, ExecutableElement autoAnnotationMethod) {
+    // We expect the return type of an @AutoAnnotation method to be an annotation type. If it isn't,
+    // AutoAnnotation will presumably complain, so we don't need to complain further.
+    TypeMirror returnType = autoAnnotationMethod.getReturnType();
+    if (!returnType.getKind().equals(TypeKind.DECLARED)) {
+      return ImmutableMap.of();
+    }
+    // This might not actually be an annotation (if the code is wrong), but if that's the case we
+    // just won't see any contained ExecutableElement where getDefaultValue() returns something.
+    TypeElement annotation = MoreTypes.asTypeElement(returnType);
+    ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
+    for (ExecutableElement method : methodsIn(annotation.getEnclosedElements())) {
+      AnnotationValue defaultValue = method.getDefaultValue();
+      if (defaultValue != null) {
+        String memberName = method.getSimpleName().toString();
+        builder.put(
+            memberName,
+            AnnotationOutput.sourceFormForInitializer(
+                defaultValue, processingEnv, memberName, autoBuilderType));
+      }
+    }
+    return builder.build();
   }
 
   private ExecutableElement findExecutable(
diff --git a/value/src/main/java/com/google/auto/value/processor/AutoValueOrBuilderTemplateVars.java b/value/src/main/java/com/google/auto/value/processor/AutoValueOrBuilderTemplateVars.java
index 86cf497..9fbc165 100644
--- a/value/src/main/java/com/google/auto/value/processor/AutoValueOrBuilderTemplateVars.java
+++ b/value/src/main/java/com/google/auto/value/processor/AutoValueOrBuilderTemplateVars.java
@@ -109,7 +109,8 @@ abstract class AutoValueOrBuilderTemplateVars extends AutoValueishTemplateVars {
    *
    * <ul>
    *   <li>it is {@code @Nullable} (in which case it defaults to null);
-   *   <li>it is {@code Optional} (in which case it defaults to empty);
+   *   <li>it has a builder initializer (for example it is {@code Optional}, which will have an
+   *       initializer of {@code Optional.empty()});
    *   <li>it has a property-builder method (in which case it defaults to empty).
    * </ul>
    */
diff --git a/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java b/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java
index 93f2f79..55a94a7 100644
--- a/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java
+++ b/value/src/main/java/com/google/auto/value/processor/AutoValueishProcessor.java
@@ -160,6 +160,7 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
     private final Optional<String> nullableAnnotation;
     private final Optionalish optional;
     private final String getter;
+    private final String builderInitializer; // empty, or with initial ` = `.
 
     Property(
         String name,
@@ -167,16 +168,40 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
         String type,
         TypeMirror typeMirror,
         Optional<String> nullableAnnotation,
-        String getter) {
+        String getter,
+        Optional<String> maybeBuilderInitializer) {
       this.name = name;
       this.identifier = identifier;
       this.type = type;
       this.typeMirror = typeMirror;
       this.nullableAnnotation = nullableAnnotation;
       this.optional = Optionalish.createIfOptional(typeMirror);
+      this.builderInitializer =
+          maybeBuilderInitializer.isPresent()
+              ? " = " + maybeBuilderInitializer.get()
+              : builderInitializer();
       this.getter = getter;
     }
 
+    /**
+     * Returns the appropriate initializer for a builder property. Builder properties are never
+     * primitive; if the built property is an {@code int} the builder property will be an {@code
+     * Integer}. So the default value for a builder property will be null unless there is an
+     * initializer. The caller of the constructor may have supplied an initializer, but otherwise we
+     * supply one only if this property is an {@code Optional} and is not {@code @Nullable}. In that
+     * case the initializer sets it to {@code Optional.empty()}.
+     */
+    private String builderInitializer() {
+      if (nullableAnnotation.isPresent()) {
+        return "";
+      }
+      Optionalish optional = Optionalish.createIfOptional(typeMirror);
+      if (optional == null) {
+        return "";
+      }
+      return " = " + optional.getEmpty();
+    }
+
     /**
      * Returns the name of the property as it should be used when declaring identifiers (fields and
      * parameters). If the original getter method was {@code foo()} then this will be {@code foo}.
@@ -218,6 +243,14 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
       return optional;
     }
 
+    /**
+     * Returns a string to be used as an initializer for a builder field for this property,
+     * including the leading {@code =}, or an empty string if there is no explicit initializer.
+     */
+    public String getBuilderInitializer() {
+      return builderInitializer;
+    }
+
     /**
      * Returns the string to use as a method annotation to indicate the nullability of this
      * property. It is either the empty string, if the property is not nullable, or an annotation
@@ -266,7 +299,8 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
           type,
           method.getReturnType(),
           nullableAnnotation,
-          method.getSimpleName().toString());
+          method.getSimpleName().toString(),
+          Optional.empty());
       this.method = method;
       this.fieldAnnotations = fieldAnnotations;
       this.methodAnnotations = methodAnnotations;
@@ -467,9 +501,9 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
 
   /** Returns the spelling to be used in the generated code for the given list of annotations. */
   static ImmutableList<String> annotationStrings(List<? extends AnnotationMirror> annotations) {
-    // TODO(b/68008628): use ImmutableList.toImmutableList() when that works.
     return annotations.stream()
         .map(AnnotationOutput::sourceFormForAnnotation)
+        .sorted() // ensures deterministic order
         .collect(toImmutableList());
   }
 
@@ -484,7 +518,7 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
    */
   static String generatedClassName(TypeElement type, String prefix) {
     String name = type.getSimpleName().toString();
-    while (type.getEnclosingElement() instanceof TypeElement) {
+    while (MoreElements.isType(type.getEnclosingElement())) {
       type = MoreElements.asType(type.getEnclosingElement());
       name = type.getSimpleName() + "_" + name;
     }
@@ -589,8 +623,9 @@ abstract class AutoValueishProcessor extends AbstractProcessor {
     List<? extends AnnotationMirror> elementAnnotations = element.getAnnotationMirrors();
     OptionalInt nullableAnnotationIndex = nullableAnnotationIndex(elementAnnotations);
     if (nullableAnnotationIndex.isPresent()) {
-      ImmutableList<String> annotations = annotationStrings(elementAnnotations);
-      return Optional.of(annotations.get(nullableAnnotationIndex.getAsInt()) + " ");
+      AnnotationMirror annotation = elementAnnotations.get(nullableAnnotationIndex.getAsInt());
+      String annotationString = AnnotationOutput.sourceFormForAnnotation(annotation);
+      return Optional.of(annotationString + " ");
     } else {
       return Optional.empty();
     }
diff --git a/value/src/main/java/com/google/auto/value/processor/BuilderMethodClassifier.java b/value/src/main/java/com/google/auto/value/processor/BuilderMethodClassifier.java
index 51773e6..a4336f5 100644
--- a/value/src/main/java/com/google/auto/value/processor/BuilderMethodClassifier.java
+++ b/value/src/main/java/com/google/auto/value/processor/BuilderMethodClassifier.java
@@ -386,14 +386,17 @@ abstract class BuilderMethodClassifier<E extends Element> {
       DeclaredType builderTypeMirror = MoreTypes.asDeclared(builderType.asType());
       ExecutableType methodMirror =
           MoreTypes.asExecutable(typeUtils.asMemberOf(builderTypeMirror, method));
-      if (TYPE_EQUIVALENCE.equivalent(methodMirror.getReturnType(), builderType.asType())) {
+      TypeMirror returnType = methodMirror.getReturnType();
+      if (typeUtils.isSubtype(builderType.asType(), returnType)
+          && !MoreTypes.isTypeOf(Object.class, returnType)) {
+        // We allow the return type to be a supertype (other than Object), to support step builders.
         TypeMirror parameterType = Iterables.getOnlyElement(methodMirror.getParameterTypes());
         propertyNameToSetters.put(
             propertyName, new PropertySetter(method, parameterType, function.get()));
       } else {
         errorReporter.reportError(
             method,
-            "[%sBuilderRet] Setter methods must return %s",
+            "[%sBuilderRet] Setter methods must return %s or a supertype",
             autoWhat(),
             builderType.asType());
       }
diff --git a/value/src/main/java/com/google/auto/value/processor/BuilderSpec.java b/value/src/main/java/com/google/auto/value/processor/BuilderSpec.java
index 9f45d17..dfdbb8c 100644
--- a/value/src/main/java/com/google/auto/value/processor/BuilderSpec.java
+++ b/value/src/main/java/com/google/auto/value/processor/BuilderSpec.java
@@ -333,7 +333,7 @@ class BuilderSpec {
       vars.builderRequiredProperties =
           vars.props.stream()
               .filter(p -> !p.isNullable())
-              .filter(p -> p.getOptional() == null)
+              .filter(p -> p.getBuilderInitializer().isEmpty())
               .filter(p -> !vars.builderPropertyBuilders.containsKey(p.getName()))
               .collect(toImmutableSet());
     }
diff --git a/value/src/main/java/com/google/auto/value/processor/autovalue.vm b/value/src/main/java/com/google/auto/value/processor/autovalue.vm
index 86cfe49..18ca827 100644
--- a/value/src/main/java/com/google/auto/value/processor/autovalue.vm
+++ b/value/src/main/java/com/google/auto/value/processor/autovalue.vm
@@ -75,15 +75,11 @@ ${modifiers}class $subclass$formalTypes extends $origClass$actualTypes {
     ## the constructor is called from the extension code.
 
     #if ($identifiers)
-
     if ($p == null) {
       throw new NullPointerException("Null $p.name");
     }
     #else
-      ## Just throw NullPointerException with no message if it's null.
-      ## The Object cast has no effect on the code but silences an ErrorProne warning.
-
-    ((`java.lang.Object`) ${p}).getClass();
+    `java.util.Objects`.requireNonNull($p);
     #end
 
   #end
diff --git a/value/src/main/java/com/google/auto/value/processor/builder.vm b/value/src/main/java/com/google/auto/value/processor/builder.vm
index 630330c..b1787f2 100644
--- a/value/src/main/java/com/google/auto/value/processor/builder.vm
+++ b/value/src/main/java/com/google/auto/value/processor/builder.vm
@@ -40,7 +40,7 @@ class ${builderName}${builderFormalTypes} ##
 
   #if ($p.kind.primitive)
 
-  private $types.boxedClass($p.typeMirror).simpleName $p;
+  private $types.boxedClass($p.typeMirror).simpleName $p $p.builderInitializer;
 
   #else
 
@@ -54,7 +54,7 @@ class ${builderName}${builderFormalTypes} ##
 
     #end
 
-  private $p.type $p #if ($p.optional && !$p.nullable) = $p.optional.empty #end ;
+  private $p.type $p $p.builderInitializer;
 
   #end
 #end
@@ -94,15 +94,11 @@ class ${builderName}${builderFormalTypes} ##
     #if (!$setter.primitiveParameter && !$p.nullable && ${setter.copy($p)} == $p)
 
       #if ($identifiers)
-
     if ($p == null) {
       throw new NullPointerException("Null $p.name");
     }
       #else
-        ## Just throw NullPointerException with no message if it's null.
-        ## The Object cast has no effect on the code but silences an ErrorProne warning.
-
-    ((`java.lang.Object`) ${p}).getClass();
+    `java.util.Objects`.requireNonNull($p);
       #end
 
     #end
diff --git a/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java b/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java
index 50b6b27..16a8a2b 100644
--- a/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java
+++ b/value/src/test/java/com/google/auto/value/processor/AutoBuilderCompilationTest.java
@@ -724,7 +724,7 @@ public final class AutoBuilderCompilationTest {
     assertThat(compilation).failed();
     assertThat(compilation)
         .hadErrorContaining(
-            "[AutoBuilderBuilderRet] Setter methods must return foo.bar.Baz.Builder")
+            "[AutoBuilderBuilderRet] Setter methods must return foo.bar.Baz.Builder or a supertype")
         .inFile(javaFileObject)
         .onLineContaining("two(int x)");
   }
diff --git a/value/src/test/java/com/google/auto/value/processor/AutoValueCompilationTest.java b/value/src/test/java/com/google/auto/value/processor/AutoValueCompilationTest.java
index ab6690f..1bb84f7 100644
--- a/value/src/test/java/com/google/auto/value/processor/AutoValueCompilationTest.java
+++ b/value/src/test/java/com/google/auto/value/processor/AutoValueCompilationTest.java
@@ -21,6 +21,7 @@ import static com.google.testing.compile.CompilationSubject.compilations;
 import static com.google.testing.compile.Compiler.javac;
 import static java.util.stream.Collectors.joining;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.ImmutableMap;
 import com.google.common.collect.ImmutableSet;
 import com.google.common.truth.Expect;
@@ -1850,6 +1851,8 @@ public class AutoValueCompilationTest {
 
   @Test
   public void autoValueBuilderSetterReturnType() {
+    // We do allow the return type of a setter to be a supertype of the builder type, to support
+    // step builders. But we don't allow it to be Object.
     JavaFileObject javaFileObject =
         JavaFileObjects.forSourceLines(
             "foo.bar.Baz",
@@ -1863,7 +1866,7 @@ public class AutoValueCompilationTest {
             "",
             "  @AutoValue.Builder",
             "  public interface Builder {",
-            "    void blim(int x);",
+            "    Object blim(int x);",
             "    Baz build();",
             "  }",
             "}");
@@ -1874,7 +1877,7 @@ public class AutoValueCompilationTest {
     assertThat(compilation)
         .hadErrorContaining("Setter methods must return foo.bar.Baz.Builder")
         .inFile(javaFileObject)
-        .onLineContaining("void blim(int x)");
+        .onLineContaining("Object blim(int x)");
   }
 
   @Test
@@ -2913,8 +2916,6 @@ public class AutoValueCompilationTest {
             "foo.bar.Bar",
             "package foo.bar;",
             "",
-            "import com.google.auto.value.AutoValue;",
-            "",
             "@" + Foo.class.getCanonicalName(),
             "public abstract class Bar {",
             "  public abstract BarFoo barFoo();",
@@ -2927,6 +2928,73 @@ public class AutoValueCompilationTest {
     assertThat(compilation).succeededWithoutWarnings();
   }
 
+  @Test
+  public void referencingGeneratedClassInAnnotation() {
+    // Test that ensures that a type that does not exist can be referenced by a copied annotation
+    // as long as it later does come into existence. The BarFoo type referenced here does not exist
+    // when the AutoValueProcessor runs on the first round, but the FooProcessor then generates it.
+    // That generation provokes a further round of annotation processing and AutoValueProcessor
+    // should succeed then.
+    // We test the three places that a class reference could appear: as the value of a Class
+    // element, as the value of a Class[] element, in a nested annotation.
+    JavaFileObject barFileObject =
+        JavaFileObjects.forSourceLines(
+            "foo.bar.Bar",
+            "package foo.bar;",
+            "",
+            "@" + Foo.class.getCanonicalName(),
+            "public abstract class Bar {",
+            "}");
+    JavaFileObject referenceClassFileObject =
+        JavaFileObjects.forSourceLines(
+            "foo.bar.ReferenceClass",
+            "package foo.bar;",
+            "",
+            "@interface ReferenceClass {",
+            "  Class<?> value() default Void.class;",
+            "  Class<?>[] values() default {};",
+            "  Nested nested() default @Nested;",
+            "  @interface Nested {",
+            "    Class<?>[] values() default {};",
+            "  }",
+            "}");
+    ImmutableList<String> annotations = ImmutableList.of(
+        "@ReferenceClass(BarFoo.class)",
+        "@ReferenceClass(values = {Void.class, BarFoo.class})",
+        "@ReferenceClass(nested = @ReferenceClass.Nested(values = {Void.class, BarFoo.class}))");
+    for (String annotation : annotations) {
+      JavaFileObject bazFileObject =
+          JavaFileObjects.forSourceLines(
+              "foo.bar.Baz",
+              "package foo.bar;",
+              "",
+              "import com.google.auto.value.AutoValue;",
+              "",
+              "@AutoValue",
+              "@AutoValue.CopyAnnotations",
+              annotation,
+              "public abstract class Baz {",
+              "  public abstract int foo();",
+              "",
+              "  public static Baz create(int foo) {",
+              "    return new AutoValue_Baz(foo);",
+              "  }",
+              "}");
+      Compilation compilation =
+          javac()
+              .withProcessors(new AutoValueProcessor(), new FooProcessor())
+              .withOptions("-Xlint:-processing", "-implicit:none")
+              .compile(bazFileObject, barFileObject, referenceClassFileObject);
+      expect.about(compilations()).that(compilation).succeededWithoutWarnings();
+      if (compilation.status().equals(Compilation.Status.SUCCESS)) {
+        expect.about(compilations()).that(compilation)
+            .generatedSourceFile("foo.bar.AutoValue_Baz")
+            .contentsAsUtf8String()
+            .contains(annotation);
+      }
+    }
+  }
+
   @Test
   public void annotationReferencesUndefined() {
     // Test that we don't throw an exception if asked to compile @SuppressWarnings(UNDEFINED)
@@ -3051,6 +3119,63 @@ public class AutoValueCompilationTest {
         .containsMatch("(?s:@Parent.ProtectedAnnotation\\s*@Override\\s*public String foo\\(\\))");
   }
 
+  @Test
+  public void methodAnnotationsCopiedInLexicographicalOrder() {
+    JavaFileObject bazFileObject =
+        JavaFileObjects.forSourceLines(
+            "foo.bar.Baz",
+            "package foo.bar;",
+            "",
+            "import com.google.auto.value.AutoValue;",
+            "import com.package1.Annotation1;",
+            "import com.package2.Annotation0;",
+            "",
+            "@AutoValue",
+            "public abstract class Baz extends Parent {",
+            "  @Annotation0",
+            "  @Annotation1",
+            "  @Override",
+            "  public abstract String foo();",
+            "}");
+    JavaFileObject parentFileObject =
+        JavaFileObjects.forSourceLines(
+            "foo.bar.Parent",
+            "package foo.bar;",
+            "",
+            "public abstract class Parent {",
+            "  public abstract String foo();",
+            "}");
+    JavaFileObject annotation1FileObject =
+        JavaFileObjects.forSourceLines(
+            "com.package1.Annotation1",
+            "package com.package1;",
+            "",
+            "import java.lang.annotation.ElementType;",
+            "import java.lang.annotation.Target;",
+            "",
+            "@Target({ElementType.FIELD, ElementType.METHOD})",
+            "public @interface Annotation1 {}");
+    JavaFileObject annotation0FileObject =
+        JavaFileObjects.forSourceLines(
+            "com.package2.Annotation0",
+            "package com.package2;",
+            "",
+            "public @interface Annotation0 {}");
+    Compilation compilation =
+        javac()
+            .withProcessors(new AutoValueProcessor())
+            .withOptions("-Xlint:-processing", "-implicit:none")
+            .compile(bazFileObject, parentFileObject, annotation1FileObject, annotation0FileObject);
+    assertThat(compilation).succeededWithoutWarnings();
+    assertThat(compilation)
+        .generatedSourceFile("foo.bar.AutoValue_Baz")
+        .contentsAsUtf8String()
+        .containsMatch(
+            "(?s:@Annotation1\\s+@Annotation0\\s+@Override\\s+public String foo\\(\\))");
+    // @Annotation1 precedes @Annotation 0 because
+    // @com.package2.Annotation1 precedes @com.package1.Annotation0
+  }
+
   @Test
   public void nonVisibleProtectedAnnotationFromOtherPackage() {
     JavaFileObject bazFileObject =
diff --git a/value/src/test/java/com/google/auto/value/processor/PropertyAnnotationsTest.java b/value/src/test/java/com/google/auto/value/processor/PropertyAnnotationsTest.java
index 48d8cd6..1d7e89f 100644
--- a/value/src/test/java/com/google/auto/value/processor/PropertyAnnotationsTest.java
+++ b/value/src/test/java/com/google/auto/value/processor/PropertyAnnotationsTest.java
@@ -510,11 +510,14 @@ public class PropertyAnnotationsTest {
                 "@PropertyAnnotationsTest.InheritedAnnotation")
             .build();
 
+    // Annotations are in lexicographical order of FQN:
+    // @com.google.auto.value.processor.PropertyAnnotationsTest.InheritedAnnotation precedes
+    // @java.lang.Deprecated
     JavaFileObject outputFile =
         new OutputFileBuilder()
             .setImports(imports)
-            .addMethodAnnotations("@Deprecated", "@PropertyAnnotationsTest.InheritedAnnotation")
-            .addFieldAnnotations("@Deprecated", "@PropertyAnnotationsTest.InheritedAnnotation")
+            .addMethodAnnotations("@PropertyAnnotationsTest.InheritedAnnotation", "@Deprecated")
+            .addFieldAnnotations("@PropertyAnnotationsTest.InheritedAnnotation", "@Deprecated")
             .build();
 
     Compilation compilation =
@@ -548,12 +551,16 @@ public class PropertyAnnotationsTest {
             .addInnerTypes("@Target(ElementType.METHOD) @interface MethodsOnly {}")
             .build();
 
+    // Annotations are in lexicographical order of FQN:
+    // @com.google.auto.value.processor.PropertyAnnotationsTest.InheritedAnnotation precedes
+    // @foo.bar.Baz.MethodsOnly precedes
+    // @java.lang.Deprecated
     JavaFileObject outputFile =
         new OutputFileBuilder()
             .setImports(getImports(PropertyAnnotationsTest.class))
-            .addFieldAnnotations("@Deprecated", "@PropertyAnnotationsTest.InheritedAnnotation")
+            .addFieldAnnotations("@PropertyAnnotationsTest.InheritedAnnotation", "@Deprecated")
             .addMethodAnnotations(
-                "@Deprecated", "@PropertyAnnotationsTest.InheritedAnnotation", "@Baz.MethodsOnly")
+                "@PropertyAnnotationsTest.InheritedAnnotation", "@Baz.MethodsOnly", "@Deprecated")
             .build();
 
     Compilation compilation =
diff --git a/value/userguide/builders-howto.md b/value/userguide/builders-howto.md
index aebdbfd..3ff8946 100644
--- a/value/userguide/builders-howto.md
+++ b/value/userguide/builders-howto.md
@@ -280,7 +280,7 @@ public abstract class Animal {
     abstract Animal autoBuild(); // not public
 
     public final Animal build() {
-      if (!name().isPresent()) {
+      if (name().isEmpty()) {
         setName(numberOfLegs() + "-legged creature");
       }
       return autoBuild();
@@ -623,11 +623,75 @@ in an exception because the required properties of `Species` have not been set.
 
 A [_step builder_](http://rdafbn.blogspot.com/2012/07/step-builder-pattern_28.html)
 is a collection of builder interfaces that take you step by step through the
-setting of each of a list of required properties. We think that these are a nice
-idea in principle but not necessarily in practice. Regardless, if you want to
-use AutoValue to implement a step builder,
-[this example](https://github.com/google/auto/issues/1000#issuecomment-792875738)
-shows you how.
+setting of each of a list of required properties. This means you can be sure at
+compile time that all the properties are set before you build, at the expense of
+some extra code and a bit less flexibility.
+
+Here is an example:
+
+```java
+@AutoValue
+public abstract class Stepped {
+  public abstract String foo();
+  public abstract String bar();
+  public abstract int baz();
+
+  public static FooStep builder() {
+    return new AutoValue_Stepped.Builder();
+  }
+
+  public interface FooStep {
+    BarStep setFoo(String foo);
+  }
+
+  public interface BarStep {
+    BazStep setBar(String bar);
+  }
+
+  public interface BazStep {
+    Build setBaz(int baz);
+  }
+
+  public interface Build {
+    Stepped build();
+  }
+
+  @AutoValue.Builder
+  abstract static class Builder implements FooStep, BarStep, BazStep, Build {}
+}
+```
+
+It might be used like this:
+
+```java
+Stepped stepped = Stepped.builder().setFoo("foo").setBar("bar").setBaz(3).build();
+```
+
+The idea is that the only way to build an instance of `Stepped`
+is to go through the steps imposed by the `FooStep`, `BarStep`, and
+`BazStep` interfaces to set the properties in order, with a final build step.
+
+Once you have set the `baz` property there is nothing else to do except build,
+so you could also combine the `setBaz` and `build` methods like this:
+
+```java
+  ...
+
+  public interface BazStep {
+    Stepped setBazAndBuild(int baz);
+  }
+
+  @AutoValue.Builder
+  abstract static class Builder implements FooStep, BarStep, BazStep {
+    abstract Builder setBaz(int baz);
+    abstract Stepped build();
+
+    @Override
+    public Stepped setBazAndBuild(int baz) {
+      return setBaz(baz).build();
+    }
+  }
+```
 
 ## <a name="autobuilder"></a> ... create a builder for something other than an `@AutoValue`?
 
diff --git a/value/userguide/howto.md b/value/userguide/howto.md
index c451185..0a7607b 100644
--- a/value/userguide/howto.md
+++ b/value/userguide/howto.md
@@ -608,7 +608,7 @@ variant as just described.
 ### Copying to the generated class
 
 If you want to copy annotations from your `@AutoValue`-annotated class to the
-generated `AutoValue_...` implemention, annotate your class with
+generated `AutoValue_...` implementation, annotate your class with
 [`@AutoValue.CopyAnnotations`].
 
 For example, if `Example.java` is:

Debdiff

[The following lists of changes regard files as different if they have different names, permissions or owners.]

Files in second set of .debs but not in first

-rw-r--r--  root/root   /usr/share/maven-repo/com/google/auto/auto-common/1.2.1/auto-common-1.2.1.pom
lrwxrwxrwx  root/root   /usr/share/java/auto-common-1.2.1.jar -> auto-common.jar
lrwxrwxrwx  root/root   /usr/share/maven-repo/com/google/auto/auto-common/1.2.1/auto-common-1.2.1.jar -> ../../../../../../java/auto-common.jar

Files in first set of .debs but not in second

-rw-r--r--  root/root   /usr/share/maven-repo/com/google/auto/auto-common/1.1.2/auto-common-1.1.2.pom
lrwxrwxrwx  root/root   /usr/share/java/auto-common-1.1.2.jar -> auto-common.jar
lrwxrwxrwx  root/root   /usr/share/maven-repo/com/google/auto/auto-common/1.1.2/auto-common-1.1.2.jar -> ../../../../../../java/auto-common.jar

No differences were encountered in the control files

More details

Full run details