bineanzhou / google-guice

Automatically exported from code.google.com/p/google-guice
Apache License 2.0
0 stars 0 forks source link

Exceptions during injection of pre-existing instances are swallowed #179

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The CreationListener created by
BindingBuilderImpl.registerInstanceForInjection catches Exception when
thrown by Injector.injectMembers. It logs the error and adds it to the
binder's errorMessages, but swallows the exception.

So any errors that occur while injecting the members of pre-existing
instances are logged but do not prevent the injector from being created.
This means that Guice.createInjector can return an invalid injector, which
would cause problems later.

This could be fixed by moving the block at BinderImpl line 276 below the
block at line 291, but I'm not sure what else would have to move with it
(maybe also line 281). (Should that block move below the preloading step at
line 298 as well?)

I think it could also be fixed by setting configurationErrorHandler to a
RuntimeErrorHandler after line 281, but that would mean that the first such
error would cause a ConfigurationException to be thrown, instead of
including those errors into a CreationException.

Original issue reported on code.google.com by net...@gmail.com on 6 Feb 2008 at 7:46

GoogleCodeExporter commented 9 years ago
Attached is a JUnit test that exercises this and the console output when 
running the
test.

Original comment by net...@gmail.com on 6 Feb 2008 at 8:02

Attachments:

GoogleCodeExporter commented 9 years ago
I've checked this test into the Guice codebase to prevent regression.

Original comment by limpbizkit on 14 May 2008 at 3:45