JDK-8210580 : java.time.ValueRange: exceptions do not match documentation
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.time
  • Affected Version: 8,11,12
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2018-09-10
  • Updated: 2024-04-03
  • Resolved: 2024-04-03
Related Reports
Duplicate :  
Description
ADDITIONAL SYSTEM INFORMATION :
Affects all OSs since library's inclusion in Java 8

A DESCRIPTION OF THE PROBLEM :
The exceptions thrown (or not thrown) by ValueRange.of (https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#of(long,long,long,long)) do not match the documentation.

STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Attempt to instantiate a ValueRange with minSmallest larger than minLargest
Attempt to instantiate a ValueRange with minSmallest larger than maxSmallest



EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
The factory throws an exception
The factory does not throw an exception 
(respectively)
ACTUAL -
The factory does not throw an exception
The factory throws an exception
(respectively)

Although I agree with the exception we _are_ getting, and feel the documentation needs to be updated to include the unlisted case.

---------- BEGIN SOURCE ----------
https://gist.github.com/Clockwork-Muse/3505cd56d254789df69725d5f9debc86
---------- END SOURCE ----------

CUSTOMER SUBMITTED WORKAROUND :
None required - exception edge cases.

FREQUENCY : always



Comments
This was resolved in https://bugs.openjdk.org/browse/JDK-8239520.
03-04-2024

There are two changes required here : 1. The documentation at https://docs.oracle.com/javase/10/docs/api/java/time/temporal/ValueRange.html#of(long,long,long,long) needs to be updated to add that IllegalArgumentException is also thrown in the case where smallest min is greater than largest min. 2. The method needs to be modified to include the case that an IllegalArgumentException is thrown when smallest min is greater than smallest max. Test Results : JDK 8u181 - Fail JDK 10.0.2 - Fail JDK 11-ea+28 - Fail JDK 12-ea - Fail
11-09-2018