commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Julien Aymé (JIRA) <>
Subject [jira] Commented: (LANG-429) NullPointerException (NPE) in FastDateFormat.getInstance(
Date Thu, 24 Apr 2008 13:53:22 GMT


Julien Aymé commented on LANG-429:

IMHO, this is rather an example of a data-race issue due to the cInstanceCache field not being
final and not being synchronized in <clinit> in FastDateFormat in Lang 2.2.

I suppose that the following scenario could explain your problem:
- at least two Threads concurrently access to FastDateFormat.getInstance() method, while FastDateFormat
is not being loaded by the current classloader:
- Thread A loads FastDateFormat.class, and creates cInstanceCache.
- Thread B enters the FastDateFormat.getInstance() method, BUT FastDateFormat.class is in
a incoherent state (cInstanceCache is null) because of memory synchronization and/or compiler
     => this causes the NullPointerException in Thread B
- Thread A enters in FastDateFormat.getInstance() method and everything is correct.

I suggest you to upgrade to Lang 2.4 in which the cInstanceCache field has been made final,
and see if this problem still occurs.

Furthermore, the semantic of final keyword has been strengthen due to JSR-133 , which is part
of Java 5.
I encourage you to read the following section:
and the Final Fields paragraph in JSR-133:

> NullPointerException (NPE) in FastDateFormat.getInstance(
> ---------------------------------------------------------------------------------
>                 Key: LANG-429
>                 URL:
>             Project: Commons Lang
>          Issue Type: Bug
>    Affects Versions: 2.2
>         Environment: MS Windows XP (SP 2), Java 1.5.0 Update 11
>            Reporter: Kai Burjack
> Sometimes (sadly this is not reproducible) the following method call results in a NullPointerException
> Stacktrace:
> java.lang.NullPointerException
>         at org.apache.commons.lang.time.FastDateFormat.getInstance(
>         at org.apache.commons.lang.time.DateFormatUtils.format(
>         at org.apache.commons.lang.time.DateFormatUtils.format(
> I don't know how this is actually possible, since the exception is being raised when
accessing a static field 'cInstanceCache' that will be implicitly initialized...
> Could this have something to do with class gc?

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

View raw message