Summary
Instant.ofEpochMilli says it can throw DateTimeException, but it cannot.
Problem
Instant.ofEpochMilli says it can throw DateTimeException, but it cannot. This means that conscientious developers may waste time trying to handle an exception that can never happen. The argument to this method is the same sort of long
as System.currentTimeMillis()
so it would actually be quite surprising if some values were not accepted.
Solution
Remove the offending @throws
clause.
Specification
diff --git a/src/java.base/share/classes/java/time/Instant.java b/src/java.base/share/classes/java/time/Instant.java
index 5c27879b6d1b..810581c42332 100644
--- a/src/java.base/share/classes/java/time/Instant.java
+++ b/src/java.base/share/classes/java/time/Instant.java
@@ -342,7 +342,6 @@ public static Instant ofEpochSecond(long epochSecond, long nanoAdjustment) {
*
* @param epochMilli the number of milliseconds from 1970-01-01T00:00:00Z
* @return an instant, not null
- * @throws DateTimeException if the instant exceeds the maximum or minimum instant
*/
public static Instant ofEpochMilli(long epochMilli) {
long secs = Math.floorDiv(epochMilli, 1000);
- csr of
-
JDK-8303919 Instant.ofEpochMilli says it can throw an exception that it can't
-
- Resolved
-