Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8159616

java.time.Instant falls through switch statement

    Details

    • Subcomponent:
    • Introduced In Version:
      8
    • Resolved In Build:
      b126
    • Verification:
      Not verified

      Description

      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.

        Activity

        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/167660ada3b1
        User: ntv
        Date: 2016-07-04 10:51:22 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/dev/jdk/rev/167660ada3b1 User: ntv Date: 2016-07-04 10:51:22 +0000
        Hide
        hgupdate HG Updates added a comment -
        URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/167660ada3b1
        User: lana
        Date: 2016-07-06 20:17:35 +0000
        Show
        hgupdate HG Updates added a comment - URL: http://hg.openjdk.java.net/jdk9/jdk9/jdk/rev/167660ada3b1 User: lana Date: 2016-07-06 20:17:35 +0000

          People

          • Assignee:
            bgopularam Bhanu Prakash Gopularam
            Reporter:
            scolebourne Stephen Colebourne
          • Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: