-
Notifications
You must be signed in to change notification settings - Fork 1.7k
ERROR_INJECTING_METHOD
Googler edited this page Aug 13, 2020
·
1 revision
Guice will throw an ERROR_INJECTING_METHOD error if a method that uses
method injection
throws an exception when called by Guice.
Example:
final class Foo {
private Bar bar;
@Inject
void setBar(Bar bar) {
this.bar = bar;
this.bar.getBaz().doSomething(); // getBaz() may return null.
}
}When Bar.getBaz() returns null, a NullPointerException will be thrown from
the setBar method causing Guice to throw an ERROR_INJECTING_METHOD error.
The fix for the Guice ERROR_INJECTING_METHOD error is to avoid throwing
exceptions from injected methods:
final class Foo {
private Bar bar;
@Inject
void setBar(Bar bar) {
this.bar = bar;
if (this.bar != null) {
this.bar.getBaz().doSomething();
}
}
}-
User's Guide
-
Integration
-
Extensions
-
Internals
-
Releases
-
Community