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

Incorrect note in Javadoc for a few RandomGenerator methods

    • Icon: CSR CSR
    • Resolution: Approved
    • Icon: P4 P4
    • 24
    • core-libs
    • None
    • minimal
    • This is a doc only change.
    • Java API
    • SE

      Summary

      Improve the @implSpec text on a few RandomGenerator methods.

      Problem

      The current @implSpec for a few methods in RandomGenerator are incorrect about the expected values of the parameters. Further, they are too specific in explaining the provisions to ensure a uniform distribution.

      Solution

      Improve the @implSpec text slightly to overcome both issues.

      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
      --- a/src/java.base/share/classes/java/util/random/RandomGenerator.java
      +++ b/src/java.base/share/classes/java/util/random/RandomGenerator.java
      
      
      @@ -809,12 +809,11 @@ default int nextInt() {
            *
            * @throws IllegalArgumentException if {@code bound} is not positive
            *
      -     * @implSpec The default implementation checks that {@code bound} is a
      -     * positive {@code int}. Then invokes {@code nextInt()}, limiting the result
      -     * to be greater than or equal zero and less than {@code bound}. If {@code bound}
      -     * is a power of two then limiting is a simple masking operation. Otherwise,
      -     * the result is re-calculated by invoking {@code nextInt()} until the
      -     * result is greater than or equal zero and less than {@code bound}.
      +     * @implSpec The default implementation checks that {@code bound} is positive.
      +     * It then invokes {@link #nextInt()} one or more times to ensure a uniform
      +     * distribution in the range 0 (inclusive)
      +     * to {@code bound} (exclusive).
      +     * It assumes the distribution of {@link #nextInt()} to be uniform.
            */
           default int nextInt(int bound) {
      
      
      @@ -835,13 +834,12 @@ default int nextInt(int bound) {
            * @throws IllegalArgumentException if {@code origin} is greater than
            *         or equal to {@code bound}
            *
      -     * @implSpec The default implementation checks that {@code origin} and
      -     * {@code bound} are positive {@code ints}. Then invokes {@code nextInt()},
      -     * limiting the result to be greater that or equal {@code origin} and less
      -     * than {@code bound}. If {@code bound} is a power of two then limiting is a
      -     * simple masking operation. Otherwise, the result is re-calculated  by
      -     * invoking {@code nextInt()} until the result is greater than or equal
      -     * {@code origin} and less than {@code bound}.
      +     * @implSpec The default implementation checks that {@code origin}
      +     * is less than {@code bound}.
      +     * It then invokes {@link #nextInt()} one or more times to ensure a uniform
      +     * distribution in the range {@code origin} (inclusive)
      +     * to {@code bound} (exclusive).
      +     * It assumes the distribution of {@link #nextInt()} to be uniform.
            */
           default int nextInt(int origin, int bound) {
      
      
      @@ -868,13 +866,11 @@ default int nextInt(int origin, int bound) {
            *
            * @throws IllegalArgumentException if {@code bound} is not positive
            *
      -     * @implSpec The default implementation checks that {@code bound} is a
      -     * positive  {@code long}. Then invokes {@code nextLong()}, limiting the
      -     * result to be greater than or equal zero and less than {@code bound}. If
      -     * {@code bound} is a power of two then limiting is a simple masking
      -     * operation. Otherwise, the result is re-calculated by invoking
      -     * {@code nextLong()} until the result is greater than or equal zero and
      -     * less than {@code bound}.
      +     * @implSpec The default implementation checks that {@code bound} is positive.
      +     * It then invokes {@link #nextLong()} one or more times to ensure a uniform
      +     * distribution in the range 0 (inclusive)
      +     * to {@code bound} (exclusive).
      +     * It assumes the distribution of {@link #nextLong()} to be uniform.
            */
           default long nextLong(long bound) {
      
      
      @@ -895,13 +891,12 @@ default long nextLong(long bound) {
            * @throws IllegalArgumentException if {@code origin} is greater than
            *         or equal to {@code bound}
            *
      -     * @implSpec The default implementation checks that {@code origin} and
      -     * {@code bound} are positive {@code longs}. Then invokes {@code nextLong()},
      -     * limiting the result to be greater than or equal {@code origin} and less
      -     * than {@code bound}. If {@code bound} is a power of two then limiting is a
      -     * simple masking operation. Otherwise, the result is re-calculated by
      -     * invoking {@code nextLong()} until the result is greater than or equal
      -     * {@code origin} and less than {@code bound}.
      +     * @implSpec The default implementation checks that {@code origin}
      +     * is less than {@code bound}.
      +     * It then invokes {@link #nextLong()} one or more times to ensure a uniform
      +     * distribution in the range {@code origin} (inclusive)
      +     * to {@code bound} (exclusive).
      +     * It assumes the distribution of {@link #nextLong()} to be uniform.
            */
           default long nextLong(long origin, long bound) {

            rgiulietti Raffaello Giulietti
            webbuggrp Webbug Group
            Brian Burkhalter
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: