commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From l..@apache.org
Subject [06/22] [math] Reverting commit fdc116f0bcda6d1fffbbe505d0687b0406e92fa6 as per Gilles request.
Date Sun, 17 Jan 2016 10:41:55 GMT
Reverting commit fdc116f0bcda6d1fffbbe505d0687b0406e92fa6 as per Gilles request.

The work on revamping the random packages is perfoemd in the random-ravamp branch.


Project: http://git-wip-us.apache.org/repos/asf/commons-math/repo
Commit: http://git-wip-us.apache.org/repos/asf/commons-math/commit/2edc62af
Tree: http://git-wip-us.apache.org/repos/asf/commons-math/tree/2edc62af
Diff: http://git-wip-us.apache.org/repos/asf/commons-math/diff/2edc62af

Branch: refs/heads/master
Commit: 2edc62af90db14bd9166eb5e0d8c62eced9351bc
Parents: 068e4f1
Author: Luc Maisonobe <luc@apache.org>
Authored: Sun Jan 17 11:30:24 2016 +0100
Committer: Luc Maisonobe <luc@apache.org>
Committed: Sun Jan 17 11:40:27 2016 +0100

----------------------------------------------------------------------
 .../apache/commons/math4/random/BaseRandomGenerator.java    | 9 +++++----
 .../commons/math4/random/BaseRandomGeneratorTest.java       | 7 +++++++
 2 files changed, 12 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/commons-math/blob/2edc62af/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java b/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
index 9907d71..bc6442e 100644
--- a/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
+++ b/src/main/java/org/apache/commons/math4/random/BaseRandomGenerator.java
@@ -200,7 +200,7 @@ public abstract class BaseRandomGenerator
      * @param start Index at which to start inserting the generated bytes.
      * @param len Number of bytes to insert.
      * @throws OutOfRangeException if {@code start < 0} or {@code start >= bytes.length}.
-     * @throws OutOfRangeException if {@code len < 0} or {@code len > bytes.length
- start}.
+     * @throws OutOfRangeException if {@code len <= 0} or {@code len > bytes.length
- start}.
      */
     public void nextBytes(byte[] bytes,
                           int start,
@@ -209,9 +209,10 @@ public abstract class BaseRandomGenerator
             start >= bytes.length) {
             throw new OutOfRangeException(start, 0, bytes.length);
         }
-        if (len < 0 ||
-            len > bytes.length - start) {
-            throw new OutOfRangeException(len, 0, bytes.length - start);
+        final int max = bytes.length - start;
+        if (len <= 0 ||
+            len > max) {
+            throw new OutOfRangeException(len, 0, max);
         }
 
         nextBytesFill(bytes, start, len);

http://git-wip-us.apache.org/repos/asf/commons-math/blob/2edc62af/src/test/java/org/apache/commons/math4/random/BaseRandomGeneratorTest.java
----------------------------------------------------------------------
diff --git a/src/test/java/org/apache/commons/math4/random/BaseRandomGeneratorTest.java b/src/test/java/org/apache/commons/math4/random/BaseRandomGeneratorTest.java
index 13b83ee..40ab9b5 100644
--- a/src/test/java/org/apache/commons/math4/random/BaseRandomGeneratorTest.java
+++ b/src/test/java/org/apache/commons/math4/random/BaseRandomGeneratorTest.java
@@ -63,6 +63,13 @@ public class BaseRandomGeneratorTest extends RandomGeneratorAbstractTest
{
     public void testNextBytesPrecondition3() {
         final int len = 3;
         final byte[] b = new byte[len];
+        baseRandomGenerator.nextBytes(b, 0, 0);
+    }
+
+    @Test(expected=OutOfRangeException.class)
+    public void testNextBytesPrecondition4() {
+        final int len = 3;
+        final byte[] b = new byte[len];
         baseRandomGenerator.nextBytes(b, 0, len + 1);
     }
 


Mime
View raw message