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;
             }

Reply via email to