JDK-4146173 : DateFormatSymbols.getWeekdays, getMonths return too many strings
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1.6
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • OS: generic
  • CPU: generic
  • Submitted: 1998-06-05
  • Updated: 2014-04-24
  • Resolved: 1998-06-12
Description

Name: moC74494			Date: 06/05/98


The getWeekdays method in DateFormatSymbols returns a String[]
that contains too many Strings. Specifically, it returns an array
of 8 Strings, with strDays[0] being an empty String.

getWeekdays should return 7 strings ("Sunday", "Monday", etc) and
should be 0-based such that strDays[0] is "Sunday" instead of an
empty string.

getMonths in DateFormatSymbols returns a String[] that contains
too many items. Specifically, it returns 13 Strings where the 
String at index 12 is empty. 

Example code follows:

//*****************************************
//Title:        DateFormatSymbols bug
//Author:       John O'Conner (###@###.###)
//Company:      QAD, Inc.
//*****************************************

import java.text.DateFormat;
import java.text.DateFormatSymbols;
import java.text.SimpleDateFormat;
import java.util.Calendar;


public class BugDemo
{

  public static void main(String[] args)
  {
    DateFormat df = DateFormat.getDateInstance();
    Calendar cal = df.getCalendar();
    int firstDay = cal.getFirstDayOfWeek();
    DateFormatSymbols symbols = ((SimpleDateFormat)df).getDateFormatSymbols();
    String strDays[] = symbols.getWeekdays();
    String strMonths[] = symbols.getMonths();

    System.out.println("strDays array length: " + strDays.length);
    for (int x = 0; x < strDays.length; x++) {
      System.out.println("strDays[" + x + "]: " + strDays[x]);
    }
    System.out.println("\n\n");

    System.out.println("strMonths array length: " + strMonths.length);
    for (int x = 0; x < strMonths.length; x++) {
      System.out.println("strMonths[" + x + "]: " + strMonths[x]);
    }

    System.exit(0);
  }
}
(Review ID: 33091)
======================================================================

Comments
EVALUATION This is not a bug, since the returned arrays are indexed by Calendar.SUNDAY, etc. The month array accomodates a possible 13th month. HENCE, this fix updates the javadoc comment for the methods getWeekdays(), setWeekdays(), getShortWeekdays(), and setShortWeekdays(). NO SPEC CHANGE. NO TEST, since this is a doc change only.
11-06-2004

WORK AROUND Name: moC74494 Date: 06/05/98 Use the String[] returned by getWeekdays as if it begins at index 1, ignoring the empty String at index 0. ======================================================================
11-06-2004