-
Bug
-
Resolution: Fixed
-
P4
-
9
In this code in java.time.Instant:
public int get(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
case NANO_OF_SECOND: return nanos;
case MICRO_OF_SECOND: return nanos / 1000;
case MILLI_OF_SECOND: return nanos / 1000_000;
case INSTANT_SECONDS: INSTANT_SECONDS.checkValidIntValue(seconds);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return range(field).checkValidIntValue(field.getFrom(this), field);
}
the INSTANT_SECONDS block falls through. The result is that passing INSTANT_SECONDS to the method sometimes throws DateTimeException and sometimes throws UnsupportedTemporalTypeException.
The correct behaviour (as per the spec) is to throw UnsupportedTemporalTypeException. As such the whole "case INSTANT_SECONDS" line should simply be removed.
See also https://github.com/ThreeTen/threetenbp/issues/41 for context.
public int get(TemporalField field) {
if (field instanceof ChronoField) {
switch ((ChronoField) field) {
case NANO_OF_SECOND: return nanos;
case MICRO_OF_SECOND: return nanos / 1000;
case MILLI_OF_SECOND: return nanos / 1000_000;
case INSTANT_SECONDS: INSTANT_SECONDS.checkValidIntValue(seconds);
}
throw new UnsupportedTemporalTypeException("Unsupported field: " + field);
}
return range(field).checkValidIntValue(field.getFrom(this), field);
}
the INSTANT_SECONDS block falls through. The result is that passing INSTANT_SECONDS to the method sometimes throws DateTimeException and sometimes throws UnsupportedTemporalTypeException.
The correct behaviour (as per the spec) is to throw UnsupportedTemporalTypeException. As such the whole "case INSTANT_SECONDS" line should simply be removed.
See also https://github.com/ThreeTen/threetenbp/issues/41 for context.