#722 RegularTimePeriod.WORKING_CALENDAR needs synchronized access

1.0.x
closed-fixed
General (896)
5
2007-03-05
2007-02-22
No

In the class RegularTimePeriod.java, the WORKING_CALENDAR constant (1) should not be a constant, and (2) could also have synchronized access.

If a JFreeChart is displaying TimeSeries data then no other thread in the application can create another TimeSeries object without risking random Calendar exceptions. This is quite a severe limitation, namely, that developers must restrict all TimeSeries and RegularTimePeriod object creation and usage to a single thread.

It appears the WORKING_CALENDAR was programmed under the assumption that Calendar objects are not mutable. However, calendars are mutable objects and should not be used as constants, and should not carry such threading limitations.

For instance, the WORKING_CALENDAR is used by the compareTo() method of the Millisecond.java class. This introduces many threading unsafe methods in the TimeSeries and RegularTimePeriod classes.

For example, consider the following stack trace we see quite frequently:

java.lang.ArrayIndexOutOfBoundsException: -441
at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(BaseCalendar.java:436)
at java.util.GregorianCalendar.computeFields(GregorianCalendar.java:2080)
at java.util.GregorianCalendar.computeTime(GregorianCalendar.java:2471)
at java.util.Calendar.updateTime(Calendar.java:2260)
at java.util.Calendar.getTimeInMillis(Calendar.java:1044)
at java.util.Calendar.getTime(Calendar.java:1017)
at org.jfree.data.time.Minute.getFirstMillisecond(Minute.java:253)
at org.jfree.data.time.Second.getFirstMillisecond(Second.java:221)
at org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:204)
at org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:191)
at org.jfree.data.time.Millisecond.getFirstMillisecond(Millisecond.java:307)
at org.jfree.data.time.Millisecond.compareTo(Millisecond.java:269)
at org.jfree.data.time.TimeSeriesDataItem.compareTo(TimeSeriesDataItem.java:207)
at java.util.Collections.indexedBinarySearch(Collections.java:217)
at java.util.Collections.binarySearch(Collections.java:203)
at org.jfree.data.time.TimeSeries.addOrUpdate(TimeSeries.java:701)

This stack trace is typical when one thread is adding items to TimeSeries A, while another thread is adding item to TimeSeries B. The WORKING_CALENDAR introduces a subtle bug that two different TimeSeries objects cannot be used simultaneously because they both might try to modify the same shared WORKING_CALENDAR at the same time, resulting in the above exception.

Discussion

  • James Vaudry

    James Vaudry - 2007-02-22

    Logged In: YES
    user_id=1651919
    Originator: YES

    Here is another similar exception, this one happens from using Millisecond and without even creating a TimeSeries object.

    java.lang.ArrayIndexOutOfBoundsException: -440
    at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(Unknown Source)
    at java.util.GregorianCalendar.computeFields(Unknown Source)
    at java.util.GregorianCalendar.computeTime(Unknown Source)
    at java.util.Calendar.updateTime(Unknown Source)
    at java.util.Calendar.getTimeInMillis(Unknown Source)
    at java.util.Calendar.getTime(Unknown Source)
    at org.jfree.data.time.Minute.getFirstMillisecond(Minute.java:253)
    at org.jfree.data.time.Second.getFirstMillisecond(Second.java:221)
    at org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:204)
    at org.jfree.data.time.RegularTimePeriod.getFirstMillisecond(RegularTimePeriod.java:191)
    at org.jfree.data.time.Millisecond.getFirstMillisecond(Millisecond.java:307)

     
  • James Vaudry

    James Vaudry - 2007-02-23

    Broken sorting is another symptom of this bug.

     
  • James Vaudry

    James Vaudry - 2007-02-23

    Logged In: YES
    user_id=1651919
    Originator: YES

    File Added: chart-picasso.JPG

     
  • David Gilbert

    David Gilbert - 2007-03-05

    Logged In: YES
    user_id=112975
    Originator: NO

    This has been fixed in 1.0.3. The WORKING_CALENDAR field has been deprecated, and is no longer used anywhere within JFreeChart.

     
  • David Gilbert

    David Gilbert - 2007-03-05
    • assigned_to: nobody --> mungady
    • status: open --> closed-fixed
     
  • Nobody/Anonymous

    Logged In: NO

    Thank you for the reply. We were using JFreeChart v1.0.1, so that explains it.

     

Log in to post a comment.