You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
however, if one forgets to annotate all dependencies with @provided (has happened to me a few times now and also to my colleague developers), then the generated class looks like this:
@Generated(
value = "com.google.auto.factory.processor.AutoFactoryProcessor",
comments = "https://github.com/google/auto/tree/master/factory"
)
final class FooFactory implements Foo.Factory {
private final Provider<String> dep1Provider;
@Inject
FooFactory(Provider<String> dep1Provider) {
this.dep1Provider = checkNotNull(dep1Provider, 1);
}
Foo create(String dep2, String runtimeDep) {
return new Foo(
checkNotNull(dep1Provider.get(), 1), checkNotNull(dep2, 2), checkNotNull(runtimeDep, 3));
}
@Override
public Foo create(String runtimeDep) {
return create(runtimeDep); // <-- recursive
}
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;
}
}
Using the method declared in the interface leads to a StackOverflowError at runtime.
Is it possible to change this? I really don't see what's good about recursively calling the factory method.
Also, would it be a good idea to not allow implementing an interface unless the non-annotated parameter list corresponds to the interface?
The text was updated successfully, but these errors were encountered:
I usually generate factories that implement an interface:
however, if one forgets to annotate all dependencies with @provided (has happened to me a few times now and also to my colleague developers), then the generated class looks like this:
Using the method declared in the interface leads to a StackOverflowError at runtime.
Is it possible to change this? I really don't see what's good about recursively calling the factory method.
Also, would it be a good idea to not allow implementing an interface unless the non-annotated parameter list corresponds to the interface?
The text was updated successfully, but these errors were encountered: