You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ah...@apache.org on 2019/05/22 12:18:10 UTC

[commons-rng] branch master updated (e73da3c -> 8eb0e21)

This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a change to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git.


    from e73da3c  Merge pull request #44 from aherbert/update-checkstyle2
     new fba6bb8  Added spotbugs exclusion for necessary null check.
     new 0fb3012  Ensure travis runs spotbugs and checkstyle checks.
     new d4bced6  synchronized at the block level.
     new 8eb0e21  JMH annotated classes cannot be final.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .travis.yml                                        |  2 +-
 .../jmh/NextBooleanGenerationPerformance.java      |  2 +-
 .../jmh/NextBytesGenerationPerformance.java        |  2 +-
 .../jmh/NextDoubleGenerationPerformance.java       |  2 +-
 .../jmh/NextFloatGenerationPerformance.java        |  2 +-
 .../examples/jmh/NextIntGenerationPerformance.java |  2 +-
 .../jmh/NextLongGenerationPerformance.java         |  2 +-
 .../apache/commons/rng/simple/JDKRandomBridge.java | 44 ++++++++++++----------
 .../checkstyle/checkstyle-suppressions.xml         |  8 ++--
 .../resources/spotbugs/spotbugs-exclude-filter.xml | 11 +++++-
 10 files changed, 46 insertions(+), 31 deletions(-)


[commons-rng] 03/04: synchronized at the block level.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit d4bced685ecb6dc84dae9add1893562b3853b646
Author: aherbert <ah...@apache.org>
AuthorDate: Wed May 22 12:25:43 2019 +0100

    synchronized at the block level.
---
 .../apache/commons/rng/simple/JDKRandomBridge.java | 44 ++++++++++++----------
 1 file changed, 25 insertions(+), 19 deletions(-)

diff --git a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/JDKRandomBridge.java b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/JDKRandomBridge.java
index 1118d4e..aa13a25 100644
--- a/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/JDKRandomBridge.java
+++ b/commons-rng-simple/src/main/java/org/apache/commons/rng/simple/JDKRandomBridge.java
@@ -65,14 +65,16 @@ public final class JDKRandomBridge extends Random {
 
     /** {@inheritDoc} */
     @Override
-    public synchronized void setSeed(long seed) {
-        if (isInitialized) {
-            delegate = RandomSource.create(source, seed);
+    public void setSeed(long seed) {
+        synchronized (this) {
+            if (isInitialized) {
+                delegate = RandomSource.create(source, seed);
 
-            // Force the clearing of the "haveNextNextGaussian" flag
-            // (cf. Javadoc of the base class); the value passed here
-            // is irrelevant (since it will not be used).
-            super.setSeed(0L);
+                // Force the clearing of the "haveNextNextGaussian" flag
+                // (cf. Javadoc of the base class); the value passed here
+                // is irrelevant (since it will not be used).
+                super.setSeed(0L);
+            }
         }
     }
 
@@ -90,37 +92,41 @@ public final class JDKRandomBridge extends Random {
      * pseudo-random 32-bits integer.
      */
     @Override
-    protected synchronized int next(int n) {
-        return delegate.nextInt() >>> (32 - n);
+    protected int next(int n) {
+        synchronized (this) {
+            return delegate.nextInt() >>> (32 - n);
+        }
     }
 
     /**
-     * @param out Output stream.
+     * @param output Output stream.
      * @throws IOException if an error occurs.
      */
-    private synchronized void writeObject(ObjectOutputStream out)
+    private void writeObject(ObjectOutputStream output)
         throws IOException {
-        // Write non-transient fields.
-        out.defaultWriteObject();
+        synchronized (this) {
+            // Write non-transient fields.
+            output.defaultWriteObject();
 
-        // Save current state.
-        out.writeObject(((RandomProviderDefaultState) delegate.saveState()).getState());
+            // Save current state.
+            output.writeObject(((RandomProviderDefaultState) delegate.saveState()).getState());
+        }
     }
 
     /**
-     * @param in Input stream.
+     * @param input Input stream.
      * @throws IOException if an error occurs.
      * @throws ClassNotFoundException if an error occurs.
      */
-    private void readObject(ObjectInputStream in)
+    private void readObject(ObjectInputStream input)
         throws IOException,
                ClassNotFoundException {
         // Read non-transient fields.
-        in.defaultReadObject();
+        input.defaultReadObject();
 
         // Recreate the "delegate" from serialized info.
         delegate = RandomSource.create(source);
         // And restore its state.
-        delegate.restoreState(new RandomProviderDefaultState((byte[]) in.readObject()));
+        delegate.restoreState(new RandomProviderDefaultState((byte[]) input.readObject()));
     }
 }


[commons-rng] 01/04: Added spotbugs exclusion for necessary null check.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit fba6bb80a4984bd8d6a74fa19f49be72a47637b3
Author: aherbert <ah...@apache.org>
AuthorDate: Wed May 22 10:39:34 2019 +0100

    Added spotbugs exclusion for necessary null check.
---
 src/main/resources/spotbugs/spotbugs-exclude-filter.xml | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/src/main/resources/spotbugs/spotbugs-exclude-filter.xml b/src/main/resources/spotbugs/spotbugs-exclude-filter.xml
index 4bc9fcc..7507b3e 100644
--- a/src/main/resources/spotbugs/spotbugs-exclude-filter.xml
+++ b/src/main/resources/spotbugs/spotbugs-exclude-filter.xml
@@ -27,13 +27,20 @@
     xsi:schemaLocation="https://github.com/spotbugs/filter/3.0.0 https://raw.githubusercontent.com/spotbugs/spotbugs/3.1.0/spotbugs/etc/findbugsfilter.xsd">
 
   <Match>
-    <Class name="~.*\.jmh\..*generated\..*" />
+    <Class name="~.*\.jmh\..*generated\..*"/>
   </Match>
 
   <Match>
     <!-- Direct access to an internal array is required for the benchmark. -->
-    <Class name="org.apache.commons.rng.examples.jmh.ConstructionPerformance$Sources" />
+    <Class name="org.apache.commons.rng.examples.jmh.ConstructionPerformance$Sources"/>
     <BugPattern name="EI_EXPOSE_REP"/>
   </Match>
 
+  <Match>
+    <!-- The EnumMap allows a null key so it must be checked for null. -->
+    <Class name="org.apache.commons.rng.simple.ThreadLocalRandomSource"/>
+    <Method name="current"/>
+    <BugPattern name="RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE"/>
+  </Match>
+
 </FindBugsFilter>


[commons-rng] 02/04: Ensure travis runs spotbugs and checkstyle checks.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 0fb3012753d1c47bac6558981ce610701e0c075d
Author: aherbert <ah...@apache.org>
AuthorDate: Wed May 22 10:44:20 2019 +0100

    Ensure travis runs spotbugs and checkstyle checks.
    
    pmd currently fails so pmd:check cannot be used.
---
 .travis.yml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/.travis.yml b/.travis.yml
index a7ec732..40f26c1 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -22,4 +22,4 @@ jdk:
   - oraclejdk9
 
 after_success:
-  - mvn clean test pmd:pmd spotbugs:spotbugs checkstyle:checkstyle jacoco:report coveralls:report
+  - mvn clean test spotbugs:check checkstyle:check jacoco:report coveralls:report


[commons-rng] 04/04: JMH annotated classes cannot be final.

Posted by ah...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-rng.git

commit 8eb0e210abb365b4a0bd6abc365e39c04b80f1d3
Author: aherbert <ah...@apache.org>
AuthorDate: Wed May 22 13:18:05 2019 +0100

    JMH annotated classes cannot be final.
---
 .../rng/examples/jmh/NextBooleanGenerationPerformance.java        | 2 +-
 .../commons/rng/examples/jmh/NextBytesGenerationPerformance.java  | 2 +-
 .../commons/rng/examples/jmh/NextDoubleGenerationPerformance.java | 2 +-
 .../commons/rng/examples/jmh/NextFloatGenerationPerformance.java  | 2 +-
 .../commons/rng/examples/jmh/NextIntGenerationPerformance.java    | 2 +-
 .../commons/rng/examples/jmh/NextLongGenerationPerformance.java   | 2 +-
 src/main/resources/checkstyle/checkstyle-suppressions.xml         | 8 +++++---
 7 files changed, 11 insertions(+), 9 deletions(-)

diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java
index e9937eb..5621c8a 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBooleanGenerationPerformance.java
@@ -31,7 +31,7 @@ public class NextBooleanGenerationPerformance extends AbstractBenchmark {
      * The benchmark state (retrieve the various "RandomSource"s).
      */
     @State(Scope.Benchmark)
-    public static final class Sources extends BaselineSources {
+    public static class Sources extends BaselineSources {
         @Override
         protected UniformRandomProvider createBaseline() {
             return BaselineUtils.getNextBoolean();
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java
index f99aaad..19041c3 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextBytesGenerationPerformance.java
@@ -31,7 +31,7 @@ public class NextBytesGenerationPerformance extends AbstractBenchmark {
      * The benchmark state (retrieve the various "RandomSource"s).
      */
     @State(Scope.Benchmark)
-    public static final class Sources extends BaselineSources {
+    public static class Sources extends BaselineSources {
         @Override
         protected UniformRandomProvider createBaseline() {
             return BaselineUtils.getNextBytes();
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java
index d917fee..cfa40b2 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextDoubleGenerationPerformance.java
@@ -31,7 +31,7 @@ public class NextDoubleGenerationPerformance extends AbstractBenchmark {
      * The benchmark state (retrieve the various "RandomSource"s).
      */
     @State(Scope.Benchmark)
-    public static final class Sources extends BaselineSources {
+    public static class Sources extends BaselineSources {
         @Override
         protected UniformRandomProvider createBaseline() {
             return BaselineUtils.getNextDouble();
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java
index 1ad9789..fbd4366 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextFloatGenerationPerformance.java
@@ -31,7 +31,7 @@ public class NextFloatGenerationPerformance extends AbstractBenchmark {
      * The benchmark state (retrieve the various "RandomSource"s).
      */
     @State(Scope.Benchmark)
-    public static final class Sources extends BaselineSources {
+    public static class Sources extends BaselineSources {
         @Override
         protected UniformRandomProvider createBaseline() {
             return BaselineUtils.getNextFloat();
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java
index 01a825b..5b582b0 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextIntGenerationPerformance.java
@@ -32,7 +32,7 @@ public class NextIntGenerationPerformance extends AbstractBenchmark {
      * The benchmark state (retrieve the various "RandomSource"s).
      */
     @State(Scope.Benchmark)
-    public static final class Sources extends BaselineSources {
+    public static class Sources extends BaselineSources {
         @Override
         protected UniformRandomProvider createBaseline() {
             return BaselineUtils.getNextInt();
diff --git a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java
index 8935dc1..f77fd7f 100644
--- a/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java
+++ b/commons-rng-examples/examples-jmh/src/main/java/org/apache/commons/rng/examples/jmh/NextLongGenerationPerformance.java
@@ -32,7 +32,7 @@ public class NextLongGenerationPerformance extends AbstractBenchmark {
      * The benchmark state (retrieve the various "RandomSource"s).
      */
     @State(Scope.Benchmark)
-    public static final class Sources extends BaselineSources {
+    public static class Sources extends BaselineSources {
         @Override
         protected UniformRandomProvider createBaseline() {
             return BaselineUtils.getNextLong();
diff --git a/src/main/resources/checkstyle/checkstyle-suppressions.xml b/src/main/resources/checkstyle/checkstyle-suppressions.xml
index 719b61e..2e182d9 100644
--- a/src/main/resources/checkstyle/checkstyle-suppressions.xml
+++ b/src/main/resources/checkstyle/checkstyle-suppressions.xml
@@ -20,8 +20,10 @@
     "https://checkstyle.org/dtds/suppressions_1_2.dtd">
 <suppressions>
   <!-- Making these final would break API compatibility. -->
-  <suppress checks="FinalClass" files="[\\/](ListSampler|InternalGamma|InternalUtils)\.java" />
+  <suppress checks="FinalClass" files="[\\/](ListSampler|InternalGamma|InternalUtils)\.java$" />
   <!-- Special cases with many parameters for the constructor. -->
-  <suppress checks="ParameterNumber" files="[\\/]LargeMeanPoissonSampler\.java" />
-  <suppress checks="ParameterNumber" files="source64[\\/].*XoShiRo512.*\.java" />
+  <suppress checks="ParameterNumber" files="[\\/]LargeMeanPoissonSampler\.java$" />
+  <suppress checks="ParameterNumber" files="source64[\\/].*XoShiRo512.*\.java$" />
+  <!-- JMH annotated classes cannot be final. -->
+  <suppress checks="DesignForExtensionCheck" files="[\\/]Next.*GenerationPerformance\.java$" />
 </suppressions>