Hi David! Since ResourceBeans are defined as implicitly being @Dependent there is also no 'late resolution' taking place. So it seems ok to throw an exception or better: to inject null if the resource cannot be found.
So if (resource.found and ok) inject resource proxy else inject null This might be needed if we have to deal with optional resources which get null-checked in the application. LieGrue, strub --- On Mon, 12/27/10, David Jencks <[email protected]> wrote: > From: David Jencks <[email protected]> > Subject: Is there a reason to produce non-working proxies from a ResourceBean? > To: [email protected] > Date: Monday, December 27, 2010, 6:07 AM > Currently ResourceBean will happily > produce proxies that can't possibly work if the > ResourceInjectionService returns null when asked for the > resource. I think this is really confusing for > users. It certainly wasted several hours of my > time. I would prefer that the ResourceBean throw an > NPE if the resource can't be found clearly indicating that > there's a problem before the unfortunate user tries to use > the proxy. > > Is there a reason for the current behavior or would this > change be fine? > > thanks > david jencks > > > proposed patch: > > Index: > webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java > =================================================================== > --- > webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java > (revision 1051320) > +++ > webbeans-impl/src/main/java/org/apache/webbeans/component/ResourceBean.java > (working copy) > @@ -53,8 +53,13 @@ > > ResourceInjectionService resourceService = > ServiceLoader.getService(ResourceInjectionService.class); > X > instance = > resourceService.getResourceReference(this.resourceReference); > > - if (instance != > null && > Modifier.isFinal(instance.getClass().getModifiers())) > + if (instance == > null) > { > + > throw new NullPointerException("No instance: " + this); > + } > + > + if > (Modifier.isFinal(instance.getClass().getModifiers())) > + { > > return instance; > > }
