]
Thomas Bauer commented on JBSEAM-1867:
--------------------------------------
Yes of course, but as it will get detected at runtime it will produce an NPE with no clue
what the problem is.
This way (I used commons-logging) I stumbled upon the bug.
But if you analyze the code (org.jboss.seam.Component:840 calls
org.jboss.seam.util.Reflections:60) you will see that it's possible that the NPE
arises if Field.set throws an IAE.
The issues I see:
Problem 1: Developer gets no response that he used the wrong type on the static field (as
the error message gets discarded)
Problem 2: There might be a case where this issue arise with another type than the logger.
And the code obviously has a weakness (as passing null as target is typical for static
fields)
NPE in org.jboss.seam.util.Reflections when an exception arise while
accessing a static field
---------------------------------------------------------------------------------------------
Key: JBSEAM-1867
URL:
http://jira.jboss.com/jira/browse/JBSEAM-1867
Project: JBoss Seam
Issue Type: Bug
Components: Core
Affects Versions: 2.0.0.BETA1
Environment: MAC OS X 10.4.10, Java(TM) 2 Runtime Environment, Standard Edition
(build 1.5.0_07-164)
Java HotSpot(TM) Client VM (build 1.5.0_07-87, mixed mode, sharing), G5 PPC
Reporter: Thomas Bauer
When an exception is thrown while accessing a static field in
org.jboss.seam.util.Reflections.get/set (org/jboss/seam/util/Reflections line 46 and 60)
the catch-block will throw a NPE when accessing the variable "target" (which is
null):
Static Fields may have target == null (e.g. call from org.jboss.seam.Component:840:
if ( Modifier.isStatic( field.getModifiers() ) )
{
Reflections.setAndWrap(field, null, logInstance); // <== HERE
'null' is passed as target
}
)
public static void set(Field field, Object target, Object value) throws Exception
{
try
{
field.set(target, value);
}
catch (IllegalArgumentException iae)
{
String message = "Could not set field value by reflection: " +
toString(field) +
" on: " + target.getClass().getName(); // <== HERE target ==
null -> NPE!
/* snipped */
}
}
This appears in:
cvs status Reflections.java
===================================================================
File: Reflections.java Status: Up-to-date
Working revision: 1.22
Repository revision: 1.22
/cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/util/Reflections.java,v
Sticky Tag: (none)
Sticky Date: (none)
Sticky Options: (none)
You can reproduce the Bug when creating a bean:
* import org.apache.commons.logging.Log instead of org.jboss.seam.log.Log
* Inject the logger: @Logger private static Log log;
Reflections.java:64: field.set(target, value);
will throw an IllegalArgumentException because it can't assign the object because of
type-mismatch
--
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: