This issues was revealed by a proposed enhanchment to JCK test for the CDC 6 TCK.
In DataeFormat.Field we have (CDC and JDK):
/**
* Creates a <code>Field</code>.
*
* @param name the name of the <code>Field</code>
* @param calendarField the <code>Calendar</code> constant this
* <code>Field</code> corresponds to; any value, even one
* outside the range of legal <code>Calendar</code> values may
* be used, but <code>-1</code> should be used for values
* that don't correspond to legal <code>Calendar</code> values
*/
protected Field(String name, int calendarField) {
super(name);
this.calendarField = calendarField;
if (this.getClass() == DateFormat.Field.class) {
instanceMap.put(name, this);
if (calendarField >= 0) {
// assert(calendarField < Calendar.FIELD_COUNT);
calendarToFieldMapping[calendarField] = this;
}
}
}
/**
* Returns the <code>Calendar</code> field associated with this
* attribute. For example, if this represents the hours field of
* a <code>Calendar</code>, this would return
* <code>Calendar.HOUR</code>. If there is no corresponding
* <code>Calendar</code> constant, this will return -1.
*
* @return Calendar constant for this field
* @see java.util.Calendar
*/
public int getCalendarField() {
return calendarField;
}
The spec language for the constructor is somewhat ambigious (mandate or recommendation?)
However, in any case, the implementation is broken for calendarField >= Calendar.FIELD_COUNT.
An array-out-of-bounds exception is clearly not compliant, with the current spec language.
It's not clear if a out-of-bounds value should be converted to -1 in the constructor, or in the getCalendarField.
Either way should satisfy the proposed test.
See also: CR 7009205 for cdc_1.6 and ojec_1.6
In DataeFormat.Field we have (CDC and JDK):
/**
* Creates a <code>Field</code>.
*
* @param name the name of the <code>Field</code>
* @param calendarField the <code>Calendar</code> constant this
* <code>Field</code> corresponds to; any value, even one
* outside the range of legal <code>Calendar</code> values may
* be used, but <code>-1</code> should be used for values
* that don't correspond to legal <code>Calendar</code> values
*/
protected Field(String name, int calendarField) {
super(name);
this.calendarField = calendarField;
if (this.getClass() == DateFormat.Field.class) {
instanceMap.put(name, this);
if (calendarField >= 0) {
// assert(calendarField < Calendar.FIELD_COUNT);
calendarToFieldMapping[calendarField] = this;
}
}
}
/**
* Returns the <code>Calendar</code> field associated with this
* attribute. For example, if this represents the hours field of
* a <code>Calendar</code>, this would return
* <code>Calendar.HOUR</code>. If there is no corresponding
* <code>Calendar</code> constant, this will return -1.
*
* @return Calendar constant for this field
* @see java.util.Calendar
*/
public int getCalendarField() {
return calendarField;
}
The spec language for the constructor is somewhat ambigious (mandate or recommendation?)
However, in any case, the implementation is broken for calendarField >= Calendar.FIELD_COUNT.
An array-out-of-bounds exception is clearly not compliant, with the current spec language.
It's not clear if a out-of-bounds value should be converted to -1 in the constructor, or in the getCalendarField.
Either way should satisfy the proposed test.
See also: CR 7009205 for cdc_1.6 and ojec_1.6
- relates to
-
JDK-7022494 (spec) java.text.DateField.getCalenderField inconsistent with constructor
-
- Closed
-