java - What does it mean when I see "Re-entry is not allowed"? -
i'm trying this.
class extends b { injector injector = guice.createinjector(this); // ......statements... }
it throwing illegalstateexception
: re-entry not allowed
com.google.inject.internal.util.$preconditions.checkstate(preconditions.java:142) @ com.google.inject.abstractmodule.configure(abstractmodule.java:55) @ com.google.inject.spi.elements$recordingbinder.install(elements.java:223) @ com.google.inject.spi.elements.getelements(elements.java:101) @ com.google.inject.internal.injectorshell$builder.build(injectorshell.java:133) @ com.google.inject.internal.internalinjectorcreator.build(internalinjectorcreator.java:103) @ com.google.inject.guice.createinjector(guice.java:95) @ com.google.inject.guice.createinjector(guice.java:72) @ com.google.inject.guice.createinjector(guice.java:62)
why happening?
the way happen if call guice.createinjector()
on same module instance inside configure
method. won't happen if call @ object construction in example. here's code reproduce stack trace.
class b extends abstractmodule { protected void configure() { } } public class extends b { injector injector; @override protected void configure() { injector = guice.createinjector(this); } } public class guicetest { public static void main(string... args) { a = new a(); injector inj = guice.createinjector(a); } }
my response on how fix is... don't this! there's never remotely reason this.
until know you're doing, should never call guice.createinjector()
more once in application, , once in main
class or in many cases in static void main
method itself.. use guice , still have never called more once in same app. idea build modules, pass them injector, , let guice inject else you. see: getting started
what trying has made try this? note: please don't answer me editing question or commenting, these 2 things invalidate answer. instead, ask new question explains you're trying do, , avoid xy problem.
Comments
Post a Comment