You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@datasketches.apache.org by le...@apache.org on 2024/05/09 16:55:21 UTC

(datasketches-memory) 01/01: Updated spotbugs and fixed all the warnings.

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

leerho pushed a commit to branch release_process_prepare
in repository https://gitbox.apache.org/repos/asf/datasketches-memory.git

commit b94db773433473b82fca2c9c33f7a1fefed4e4bb
Author: Lee Rhodes <le...@users.noreply.github.com>
AuthorDate: Thu May 9 09:55:13 2024 -0700

    Updated spotbugs and fixed all the warnings.
---
 .../memory/internal/AllocateDirectMap.java         | 40 +++++++++--
 .../datasketches/memory/internal/Utf8Test.java     |  2 +
 tools/FindBugsExcludeFilter.xml                    | 79 +++++-----------------
 3 files changed, 53 insertions(+), 68 deletions(-)

diff --git a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
index 6126fac..6cb5eec 100644
--- a/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
+++ b/datasketches-memory-java8/src/main/java/org/apache/datasketches/memory/internal/AllocateDirectMap.java
@@ -103,23 +103,51 @@ class AllocateDirectMap implements Map {
   final boolean resourceReadOnly;
 
   //called from AllocateDirectWritableMap constructor
-  AllocateDirectMap(final File file, final long fileOffsetBytes, final long capacityBytes,
+  AllocateDirectMap(
+      final File file,
+      final long fileOffsetBytes,
+      final long capacityBytes,
+      final boolean localReadOnly) {
+    this(check(file, fileOffsetBytes, capacityBytes, localReadOnly),
+        //SpotBugs CT_CONSTRUCTOR_THROW is false positive.
+        //this construction scheme is compliant with SEI CERT Oracle Coding Standard for Java / OBJ11-J
+        file,
+        fileOffsetBytes,
+        capacityBytes,
+        localReadOnly);
+  }
+
+  private AllocateDirectMap(
+      final boolean secure, //required part of Finalizer Attack prevention
+      final File file,
+      final long fileOffsetBytes,
+      final long capacityBytes,
       final boolean localReadOnly) {
     this.capacityBytes = capacityBytes;
-    resourceReadOnly = isFileReadOnly(file);
+    this.resourceReadOnly = isFileReadOnly(file);
+    this.raf = mapper(file, fileOffsetBytes, capacityBytes, resourceReadOnly);
+    this.nativeBaseOffset = map(raf.getChannel(), resourceReadOnly, fileOffsetBytes, capacityBytes);
+    this.deallocator = new Deallocator(nativeBaseOffset, capacityBytes, raf);
+    this.cleaner = new MemoryCleaner(this, deallocator);
+  }
+
+  private static final boolean check(
+      final File file,
+      final long fileOffsetBytes,
+      final long capacityBytes,
+      final boolean localReadOnly) {
     final long fileLength = file.length();
+    final boolean resourceReadOnly = isFileReadOnly(file);
     if ((localReadOnly || resourceReadOnly) && fileOffsetBytes + capacityBytes > fileLength) {
       throw new IllegalArgumentException(
           "Read-only mode and requested map length is greater than current file length: "
           + "Requested Length = " + (fileOffsetBytes + capacityBytes)
           + ", Current File Length = " + fileLength);
     }
-    raf = mapper(file, fileOffsetBytes, capacityBytes, resourceReadOnly);
-    nativeBaseOffset = map(raf.getChannel(), resourceReadOnly, fileOffsetBytes, capacityBytes);
-    deallocator = new Deallocator(nativeBaseOffset, capacityBytes, raf);
-    cleaner = new MemoryCleaner(this, deallocator);
+    return true;
   }
 
+
   //Map Interface
 
   @Override
diff --git a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java
index 762efe3..483535c 100644
--- a/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java
+++ b/datasketches-memory-java8/src/test/java/org/apache/datasketches/memory/internal/Utf8Test.java
@@ -27,6 +27,7 @@ import java.io.IOException;
 import java.nio.CharBuffer;
 import java.util.ArrayList;
 import java.util.List;
+import java.util.Objects;
 
 import org.apache.datasketches.memory.Memory;
 import org.apache.datasketches.memory.Utf8CodingException;
@@ -244,6 +245,7 @@ public class Utf8Test {
     //checks the non-deterministic constructor
     @SuppressWarnings("unused")
     RandomCodePoints rcp = new RandomCodePoints(false);
+    Objects.requireNonNull(rcp);
   }
 
 
diff --git a/tools/FindBugsExcludeFilter.xml b/tools/FindBugsExcludeFilter.xml
index ae68389..62b7101 100644
--- a/tools/FindBugsExcludeFilter.xml
+++ b/tools/FindBugsExcludeFilter.xml
@@ -21,76 +21,31 @@ under the License.
 
 <FindBugsFilter> <!-- memory -->
 
+  <!-- Ignore all test code -->
+  <Match>
+    <Class name="~.*\.*Test" />
+  </Match>
+
   <!-- Too many false positives to be useful.  I could not make it happy :( -->
   <Match>
     <Bug pattern="SF_SWITCH_NO_DEFAULT" />
   </Match>
 
-  <Match>   <!-- Exclude for test classes; too many False Positives. -->
-    <Bug pattern="NP_NULL_PARAM_DEREF_NONVIRTUAL" />
-    <Class name="~.*\.*Test" />
+  <!-- Complaining about copying of data from one internal class to another. 
+       This is harmless since both classes are part of our library internals and work together. -->
+  <Match>
+    <Bug pattern="EI_EXPOSE_REP"/>
+    <Or>
+      <Class name="org.apache.datasketches.memory.internal.WritableDirectHandleImpl"/>
+      <Class name="org.apache.datasketches.memory.internal.WritableMapHandleImpl"/>
+      <Class name="org.apache.datasketches.memory.internal.MapHandleImpl"/>
+    </Or>
   </Match>
   
-  <Match>   <!-- Exclude for test classes; too many False Positives. -->
-    <Bug pattern="DLS_DEAD_LOCAL_STORE" />
-    <Class name="~.*\.*Test" />
+  <Match> <!-- False Positive: Code is the recommended solution for preventing a Finalizer Attack. -->
+    <Bug pattern="CT_CONSTRUCTOR_THROW" />
+    <Class name="org.apache.datasketches.memory.internal.AllocateDirectMap"/>
   </Match>
   
 </FindBugsFilter>
 
-
-
-<!--  Examples: -->
-
-<!-- Exclude java.* classes -->
-  <!--
-  <Match>
-    <Package name="java\.*" />
-  </Match>
--->
-
-  <!-- Exclude test classes -->
-<!-- 
-  <Match>
-    <Class name="~.*\.*Test" />
-  </Match>
--->
-
-<!--
-     <Match>
-       <Class name="com.foobar.ClassNotToBeAnalyzed" />
-     </Match>
--->
-<!--
-     <Match>
-       <Class name="com.foobar.ClassWithSomeBugsMatched" />
-       <Bug code="DE,UrF,SIC" />
-     </Match>
--->
-     <!-- Match all XYZ violations. -->
-<!--
-     <Match>
-       <Bug code="XYZ" />
-     </Match>
--->
-     <!-- Match all doublecheck violations in these methods of "AnotherClass". -->
-<!--
-     <Match>
-       <Class name="com.foobar.AnotherClass" />
-       <Or>
-         <Method name="nonOverloadedMethod" />
-         <Method name="frob" params="int,java.lang.String" returns="void" />
-         <Method name="blat" params="" returns="boolean" />
-       </Or>
-       <Bug code="DC" />
-     </Match>
--->
-     <!-- A method with a dead local store false positive (medium priority). -->
-<!--
-     <Match>
-       <Class name="com.foobar.MyClass" />
-       <Method name="someMethod" />
-       <Bug pattern="DLS_DEAD_LOCAL_STORE" />
-       <Priority value="2" />
-     </Match>
--->


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@datasketches.apache.org
For additional commands, e-mail: commits-help@datasketches.apache.org