Clarify error message when a user's method on a component conflicts with a generated component creator method.
Fixes #3512.
RELNOTES=n/a
PiperOrigin-RevId: 468794941
diff --git a/java/dagger/internal/codegen/writing/ComponentImplementation.java b/java/dagger/internal/codegen/writing/ComponentImplementation.java
index 30df288..4463e4d 100644
--- a/java/dagger/internal/codegen/writing/ComponentImplementation.java
+++ b/java/dagger/internal/codegen/writing/ComponentImplementation.java
@@ -830,8 +830,11 @@
messager.printMessage(
ERROR,
String.format(
- "Cannot override generated method: %s.%s()",
- getSimpleName(method.getEnclosingElement()), getSimpleName(method))));
+ "The method %s.%s() conflicts with a method of the same name Dagger is "
+ + "trying to generate as a way to instantiate the component. Please "
+ + "choose a different name for your method.",
+ method.getEnclosingElement().getClassName().canonicalName(),
+ getSimpleName(method))));
}
/** {@code true} if all of the graph's required dependencies can be automatically constructed */
diff --git a/javatests/dagger/internal/codegen/ComponentValidationTest.java b/javatests/dagger/internal/codegen/ComponentValidationTest.java
index 1575111..26e660d 100644
--- a/javatests/dagger/internal/codegen/ComponentValidationTest.java
+++ b/javatests/dagger/internal/codegen/ComponentValidationTest.java
@@ -74,7 +74,7 @@
Compilation compilation = daggerCompiler().compile(componentFile, moduleFile);
assertThat(compilation).failed();
assertThat(compilation)
- .hadErrorContaining("Cannot override generated method: TestComponent.builder()");
+ .hadErrorContaining("The method test.TestComponent.builder() conflicts with a method");
}
@Test
@@ -107,7 +107,7 @@
Compilation compilation = daggerCompiler().compile(componentFile, moduleFile);
assertThat(compilation).failed();
assertThat(compilation)
- .hadErrorContaining("Cannot override generated method: TestComponent.create()");
+ .hadErrorContaining("The method test.TestComponent.create() conflicts with a method");
}
@Test