commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Benedikt Ritter (JIRA)" <>
Subject [jira] [Commented] (SANDBOX-433) [BeanUtils2] Setting properties or calling methods very often results in a NullPointerException
Date Sun, 29 Jul 2012 14:00:34 GMT


Benedikt Ritter commented on SANDBOX-433:

I had a look at the code and it appears that the problem results from our caching implementation
in AccessibleObjectsRegistry and PropertyDescriptorRegistry. Both classes use something like:

private final Map<AccessibleObjectDescriptor, Reference<AO>> cache = 
   WeakHashMap<AccessibleObjectDescriptor, WeakReference<AO>>();

Now I'm not an expert when it comes to references, but judging from the JavaDoc of [WeakHashMap|]
and [WeakReference|]
we have created a cache that will delete hole entries as their keys expire from the point
of view of the WeakHashMap. Also values can be cleaned up, when the JVM determines it. That
leaves broken entries in the cache, that have a key but null as a value. Later on when we
query for a key we will get a null reference resulting in an NullPointerException.

I have changed the implementation to use [SoftReferences|]
and that works. However it may only work in my test scenario and throw an NPE when one calls
a method more often (than 50.000 times).
As I said at the beginning, I'm no expert when it comes to java.lang.ref. I would say that
there is no need for a reference at all. We could simply change the initialization to:

private final Map<AccessibleObjectDescriptor, AO> cache = 
   WeakHashMap<AccessibleObjectDescriptor, AO>();

The WeakHashMap will take care of cleaning up references that are not longer in use.
If nobody objects, I can create a patch for this.

> [BeanUtils2] Setting properties or calling methods very often results in a NullPointerException
> -----------------------------------------------------------------------------------------------
>                 Key: SANDBOX-433
>                 URL:
>             Project: Commons Sandbox
>          Issue Type: Bug
>          Components: BeanUtils2
>            Reporter: Benedikt Ritter
>         Attachments: SANDBOX-433-TestCase.patch
> If a property get accessed too often, a NullPointerException will be thrown. The same
is true for calling methods several times.
> In my configuration I'm seeing a NPE after about 27.000 calls.
> Calling constructors very often does seem to work.

This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:!default.jspa
For more information on JIRA, see:


View raw message