Skip to Main Content

Bug Detection in Calendar.getDisplayName

L.D.L.Mar 30 2015 — edited Mar 31 2015

Operating System = Windows 7 version 6.1 running on amd64

Java; VM; Vendor = 1.8.0

Runtime = Java HotSpot(TM) 64-Bit Server VM 25.0-b70

Detect a bug in Java, specifically in the Calendar class will getDisplayName method. I put in the message code showing the error. If the code is executed you can see that the month March be repeated 2 times jumping the month of February.

Code Example:

import java.util.Calendar;

import java.util.Locale;

public class BugInCalendarDisplayName {

  public static void main(String[] args) {

    Calendar aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 0);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 1);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 2);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 3);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 4);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 5);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 6);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 7);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 8);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 9);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 10);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

    aMonth = Calendar.getInstance();

    aMonth.set(Calendar.MONTH, 11);

    System.out.println(aMonth.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault()).toUpperCase());

  }

}

Obtained results of the code execution:

ENERO

MARZO

MARZO

ABRIL

MAYO

JUNIO

JULIO

AGOSTO

SEPTIEMBRE

OCTUBRE

NOVIEMBRE

DICIEMBRE

Comments
Post Details
Added on Mar 30 2015
3 comments
973 views