-
Bug
-
Resolution: Fixed
-
P4
-
6
-
b21
-
generic
-
windows_xp
There are two problems here:
1. The spec for is
"protected DateFormat.Field(String name,
int calendarField)
Creates a Field with the specified name. calendarField is used to identify the Calendar field this attribute represents. Use -1 if this field does not have a corresponding Calendar value."
The behaviour of constructor is undefined when calendarField is not from
range -1 .. Calendar.FIELD_COUNT (not legal calendar field and not -1).
It is not very clear if any out of range value is allowed or not.
2) The spec for getCalendarField() states that method returns -1 if the value is out of range. However, when running the following testcode on jdk6, it returns the value passed to the constructor.
Here is the test code:
===========================================================
public class Test {
public void case1() {
int[] values = { Integer.MIN_VALUE, -100, Integer.MAX_VALUE };
for(int i = 0; i < values.length; i++) {
StubDateFormatField mF = new StubDateFormatField("Test", values[i]);
if (mF.getCalendarField() != -1) {
System.out.println("getCalendarField() returns non -1 for "+ values[i]);
} else {
System.out.println("ok");
}
}
}
public static void main(String[] args) {
Test t = new Test();
t.case1();
}
}
class StubDateFormatField extends Field {
public StubDateFormatField(String name, int calendarField) {
super(name, calendarField);
}
}
==================================================================================
Here is the result on jdk6:
getCalendarField() returns non -1 for -2147483648
getCalendarField() returns non -1 for -100
getCalendarField() returns non -1 for 2147483647
So the implementation is inconsistent with the spec, and either one should be fixed.
1. The spec for is
"protected DateFormat.Field(String name,
int calendarField)
Creates a Field with the specified name. calendarField is used to identify the Calendar field this attribute represents. Use -1 if this field does not have a corresponding Calendar value."
The behaviour of constructor is undefined when calendarField is not from
range -1 .. Calendar.FIELD_COUNT (not legal calendar field and not -1).
It is not very clear if any out of range value is allowed or not.
2) The spec for getCalendarField() states that method returns -1 if the value is out of range. However, when running the following testcode on jdk6, it returns the value passed to the constructor.
Here is the test code:
===========================================================
public class Test {
public void case1() {
int[] values = { Integer.MIN_VALUE, -100, Integer.MAX_VALUE };
for(int i = 0; i < values.length; i++) {
StubDateFormatField mF = new StubDateFormatField("Test", values[i]);
if (mF.getCalendarField() != -1) {
System.out.println("getCalendarField() returns non -1 for "+ values[i]);
} else {
System.out.println("ok");
}
}
}
public static void main(String[] args) {
Test t = new Test();
t.case1();
}
}
class StubDateFormatField extends Field {
public StubDateFormatField(String name, int calendarField) {
super(name, calendarField);
}
}
==================================================================================
Here is the result on jdk6:
getCalendarField() returns non -1 for -2147483648
getCalendarField() returns non -1 for -100
getCalendarField() returns non -1 for 2147483647
So the implementation is inconsistent with the spec, and either one should be fixed.
- csr for
-
JDK-8318035 [Doc] Inconsistenency between the spec and the implementation for DateFormat.Field
-
- Closed
-
- relates to
-
JDK-6201179 [Fmt-Da] Doc: The behaviour of DateFormat.Field is undefined
-
- Resolved
-