Help save net neutrality! Learn more.

#977 DateAxis threading issue

General (896)

The createStandardDateTickUnits method is static. It uses SimpleDateFormat which uses Calendar which is not thread safe.

This causes random exceptions such as:
java.lang.ArrayIndexOutOfBoundsException: 84
at sun.util.calendar.BaseCalendar.getCalendarDateFromFixedDate(
at java.util.GregorianCalendar.computeFields(
at java.util.GregorianCalendar.computeFields(
at java.util.Calendar.setTimeInMillis(
at java.util.Calendar.setTime(
at java.text.SimpleDateFormat.format(
at java.text.SimpleDateFormat.format(
at java.text.DateFormat.format(
at org.jfree.chart.axis.DateTickUnit.dateToString(


  • Scott Dudley

    Scott Dudley - 2013-11-15

    I believe the problem is not in the static createStandardDateTickUnits method (static methods are not inherently bad), but rather, in the following static initializer in DateAxis, which later gets used in the constructor:

        /** The default date tick unit. */
        public static final DateTickUnit DEFAULT_DATE_TICK_UNIT
                = new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat());
        public DateAxis(String label, TimeZone zone, Locale locale) {
            super(label, DateAxis.createStandardDateTickUnits(zone, locale));
            setTickUnit(DateAxis.DEFAULT_DATE_TICK_UNIT, false, false);

    You should be able to fix this easily in your own code by calling something like this after creating the object:

     axis.setTickUnit(new DateTickUnit(DateTickUnitType.DAY, 1, new SimpleDateFormat()), false, false);
  • David Gilbert

    David Gilbert - 2013-11-23

    Thanks for the analysis. For the 1.0.17 release, I have deprecated the DEFAULT_DATE_TICK_UNIT constant and replaced its use in the code with a newly created instance.

  • David Gilbert

    David Gilbert - 2013-11-23
    • status: open --> closed-fixed
    • assigned_to: David Gilbert
    • Group: --> 1.0.x

Log in to post a comment.