gnodet commented on code in PR #12753:
URL: https://github.com/apache/maven/pull/12753#discussion_r3796358302
##########
api/maven-api-core/src/main/java/org/apache/maven/api/MonotonicClock.java:
##########
@@ -146,27 +148,50 @@ public Duration elapsedTime() {
}
/**
- * Returns the zone ID of this clock, which is always UTC.
+ * Returns the zone ID of this clock.
+ * <p>
+ * The singleton instance always returns UTC. Clock instances created
+ * via {@link #withZone(ZoneId)} return their configured timezone.
*
- * @return the UTC zone ID
+ * @return the zone ID
*/
@Override
public ZoneId getZone() {
- return ZoneOffset.UTC;
+ return zone;
}
/**
- * Returns this clock since timezone adjustments are not supported.
+ * Returns a copy of this clock with the specified timezone.
* <p>
- * This implementation maintains UTC time to ensure monotonic behavior.
- * The provided zone parameter is ignored.
+ * Since {@link Instant} instances are timezone-agnostic and the monotonic
+ * property derives from {@link System#nanoTime()}, the returned clock
+ * maintains identical monotonic timing but reports the requested timezone.
*
- * @param zone the target timezone (ignored)
- * @return this clock instance
+ * @param zone the target timezone, or {@code null} to use UTC
+ * @return a new clock with the specified timezone
+ * @throws IllegalArgumentException if zone is {@code null}
Review Comment:
**Contradictory Javadoc + wrong exception type**: The `@param` says _"or
{@code null} to use UTC"_ but the code throws on null — the `@param` should say
`@param zone the target timezone, not null`.
Also, the JDK `Clock.withZone()` convention uses `NullPointerException` (via
`Objects.requireNonNull`), not `IllegalArgumentException`. Consider:
```suggestion
public Clock withZone(ZoneId zone) {
java.util.Objects.requireNonNull(zone, "zone");
if (zone.equals(this.zone)) {
return this;
}
return new MonotonicClock(startNanos, startInstant, zone);
}
```
This also adds the same-zone optimization (returns `this` when the zone
matches, matching JDK convention).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]