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

IsoFields WEEK_BASED_YEAR and QUARTER_OF_YEAR too lenient



    • Bug
    • Resolution: Fixed
    • P4
    • 9
    • 9
    • core-libs
    • None
    • b119


      The IsoFields class WEEK_BASED_YEAR and QUARTER_OF_YEAR constants are loo lenient in their implementation of rangeRefinedBy(TemporalAccessor).

      TemporalAccessor defines rangeRefinedBy() as:

           * Gets the range of valid values for the specified field.
           * <p>
           * All fields can be expressed as a {@code long} integer.
           * This method returns an object that describes the valid range for that value.
           * The value of this temporal object is used to enhance the accuracy of the returned range.
           * If the date-time cannot return the range, because the field is unsupported or for
           * some other reason, an exception will be thrown.
           * @implSpec
           * Implementations must check and handle all fields defined in {@link ChronoField}.
           * If the field is supported, then the range of the field must be returned.
           * If unsupported, then an {@code UnsupportedTemporalTypeException} must be thrown.

      TemporalAccessor defines isSupported() as:

           * Checks if the specified field is supported.
           * <p>
           * This checks if the date-time can be queried for the specified field.
           * If false, then calling the {@link #range(TemporalField) range} and {@link #get(TemporalField) get}
           * methods will throw an exception.

      If rangeRefinedBy() is invoked on IsoFields.QUARTER_OF_YEAR or WEEK_BASED_YEAR passing an instance of ThaiBuddhuistDate, or any other non-ISO calendar system, the no exception is observed, yet the spec clearly indicates it should. Specifically, since isSuported(thaiDate) returns false, rangeRefinedBy(thaiDate) should throw an exception, but it does not.

      The change needed is to check that the temporal is based on ISO using isIso(TemporalAccessor) that already exists in IsoFields.


        Issue Links



              bgopularam Bhanu Prakash Gopularam (Inactive)
              scolebourne Stephen Colebourne
              0 Vote for this issue
              2 Start watching this issue