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

RandomGenerator nextDouble(double, double) is documented incorrectly

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 19
    • core-libs
    • None
    • behavioral
    • minimal
    • Informative change only - make the spec match the implementation.
    • Java API
    • SE

      Summary

      The current RandomGenerator javadoc for default float nextFloat(float origin, float bound) and default double nextDouble(double origin, double bound) does not describe the argument bounds correctly.

      Problem

      The current @throws and @implSpec imply that the values must be positive, which doesn't reflect reality.

      Solution

      Correct the javadoc to indicate the correct ranges,

      Specification

      diff --git a/src/java.base/share/classes/java/util/random/RandomGenerator.java b/src/java.base/share/classes/java/util/random/RandomGenerator.java
      index a5e20e55161..a28d3eb00e0 100644
      --- a/src/java.base/share/classes/java/util/random/RandomGenerator.java
      +++ b/src/java.base/share/classes/java/util/random/RandomGenerator.java
      @@ -539,13 +539,15 @@ public interface RandomGenerator {
            *
            * @throws IllegalArgumentException if {@code origin} is not finite,
            *         or {@code bound} is not finite, or {@code origin}
      -     *         is greater than or equal to {@code bound}
      -     *
      -     * @implSpec The default implementation checks that {@code origin} and
      -     * {@code bound} are positive finite floats. Then invokes
      -     * {@code nextFloat()}, scaling and translating the result so that the final
      -     * result lies between {@code origin} (inclusive) and {@code bound}
      -     * (exclusive).
      +     *         is greater than or equal to {@code bound}, or
      +     *         the difference between {@code bound} and {@code origin}
      +     *         is so large that it cannot be represented as a finite
      +     *         {@code float} value
      +     *
      +     * @implSpec The default implementation verifies that the {@code origin}
      +     *           and {@code bound} are valid then invokes {@code nextFloat()}
      +     *           scaling and translating the result to fit between {@code origin} and
      +     *           {@code bound} (exclusive).
            */
           default float nextFloat(float origin, float bound) {
               RandomSupport.checkRange(origin, bound);
      @@ -603,13 +605,15 @@ public interface RandomGenerator {
            *
            * @throws IllegalArgumentException if {@code origin} is not finite,
            *         or {@code bound} is not finite, or {@code origin}
      -     *         is greater than or equal to {@code bound}
      -     *
      -     * @implSpec The default implementation checks that {@code origin} and
      -     * {@code bound} are positive finite doubles. Then calls
      -     * {@code nextDouble()}, scaling and translating the result so that the final
      -     * result lies between {@code origin} (inclusive) and {@code bound}
      -     * (exclusive).
      +     *         is greater than or equal to {@code bound}, or
      +     *         the difference between {@code bound} and {@code origin}
      +     *         is so large that it cannot be represented as a finite
      +     *         {@code double} value
      +     *
      +     * @implSpec The default implementation verifies that the {@code origin}
      +     *           and {@code bound} are valid, then invokes {@code nextDouble()}
      +     *           scaling and translating the result to fit between {@code origin} and
      +     *           {@code bound}( exclusive).
            */
           default double nextDouble(double origin, double bound) {
               RandomSupport.checkRange(origin, bound);

            jlaskey Jim Laskey
            webbuggrp Webbug Group
            Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: