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

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


The following commit(s) were added to refs/heads/update_7.0.X by this push:
     new a9d6b584 update 7.0.X
a9d6b584 is described below

commit a9d6b584a29eebd600efe0354ad6723775634792
Author: Lee Rhodes <[email protected]>
AuthorDate: Sat May 9 11:04:18 2026 -0700

    update 7.0.X
---
 .../org/apache/datasketches/memory/internal/Util.java   | 17 +++++++++++------
 .../memory/internal/AllocateDirectMapMemoryTest.java    |  6 +++---
 .../apache/datasketches/memory/internal/UtilTest.java   | 14 ++++++--------
 3 files changed, 20 insertions(+), 17 deletions(-)

diff --git 
a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/Util.java
 
b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/Util.java
index bf226d85..a05deb57 100644
--- 
a/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/Util.java
+++ 
b/datasketches-memory-java11/src/main/java/org/apache/datasketches/memory/internal/Util.java
@@ -29,7 +29,6 @@ import java.net.URISyntaxException;
 import java.net.URL;
 import java.nio.ByteOrder;
 import java.nio.file.Files;
-import java.nio.file.Path;
 import java.nio.file.StandardCopyOption;
 import java.util.Objects;
 import java.util.Random;
@@ -295,6 +294,9 @@ public final class Util {
 
   /**
    * Returns a byte array of the contents of the file defined by the given 
resourceName.
+   * This is only used in test.
+   * If the resource is in a JAR it will be copied into the File System as a 
temporary file first.
+   * 
    * @param resourceName the short name or the full path name.
    * @return a byte array of the contents of the file defined by the given 
resourceName.
    */
@@ -307,22 +309,25 @@ public final class Util {
   }
 
   /**
-   * Checks if the given resourceName exists and sets it to Read-Only.  
+   * Checks if the given resourceName exists and sets it to Read-Only.  This 
is only used in test.
    * If the resource is in a JAR it will be copied into the File System as a 
temporary file first.
-   * This will not work if the file is currently memory-mapped.  If it is 
memory-mapped, close the mapping first.
-   * @param resourceName the given resource 
+   * This will not work if the file is currently memory-mapped.  
+   * If it is memory-mapped, close the mapping first.
+   * @param resourceName the given resource.
+   * @return File the read only file.
    */
-  public static void ensureReadOnly(final String resourceName) {
+  public static File ensureReadOnly(final String resourceName) {
       final File file = getResourceFile(resourceName);
       if (!file.exists()) {
         throw new IllegalArgumentException("File not found.");
       }
       // Works on Windows and POSIX)
       file.setReadOnly();
+      return file;
   }
   
   /**
-   *   Windows and JAR friendly get Resource File.
+   *   Windows and JAR friendly get Resource File. This is only used in test.
    *   If the resource is in a JAR it will be copied into the File System as a 
temporary file first.
    *   @param resourceName the simple file name or full path name. 
    *   Any back-slashes will be converted to forward slashes and a leading 
forward slash will be removed.
diff --git 
a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
 
b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
index ec4c2d46..ce8b33ac 100644
--- 
a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
+++ 
b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java
@@ -23,6 +23,7 @@
 
 package org.apache.datasketches.memory.internal;
 
+import static org.apache.datasketches.memory.internal.Util.ensureReadOnly;
 import static org.apache.datasketches.memory.internal.Util.getResourceFile;
 import static org.testng.Assert.assertEquals;
 import static org.testng.Assert.assertTrue;
@@ -47,11 +48,10 @@ public class AllocateDirectMapMemoryTest {
 
   @Test(expectedExceptions = IllegalStateException.class)
   public void simpleMap() throws IOException {
-    File file = getResourceFile("GettysburgAddress.txt");
-    assertTrue(AllocateDirectWritableMap.isFileReadOnly(file));
+    File file = ensureReadOnly("GettysburgAddress.txt");
     try (Memory mem = Memory.map(file)) {
       mem.close(); //explicit close
-    } //The Try-With-Resources will throw if already closed
+    } //The Try-With-Resources will throw
   }
 
   @Test
diff --git 
a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
 
b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
index da03f621..68ae05a0 100644
--- 
a/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
+++ 
b/datasketches-memory-java11/src/test/java/org/apache/datasketches/memory/internal/UtilTest.java
@@ -20,6 +20,7 @@
 package org.apache.datasketches.memory.internal;
 
 import static org.apache.datasketches.memory.internal.Util.characterPad;
+import static org.apache.datasketches.memory.internal.Util.ensureReadOnly;
 import static org.apache.datasketches.memory.internal.Util.getResourceBytes;
 import static org.apache.datasketches.memory.internal.Util.getResourceFile;
 import static org.apache.datasketches.memory.internal.Util.negativeCheck;
@@ -128,12 +129,7 @@ public class UtilTest {
   }
 
   static final void setGettysburgAddressFileToReadOnly() {
-    File file = getResourceFile("GettysburgAddress.txt");
-    try {
-      Files.setPosixFilePermissions(file.toPath(), 
PosixFilePermissions.fromString("r--r--r--"));
-    } catch (IOException e) {
-      throw new RuntimeException(e);
-    }
+    ensureReadOnly("GettysburgAddress.txt");
   }
 
   //Resources
@@ -160,10 +156,12 @@ public class UtilTest {
     assertTrue(bytes.length == 1541);
   }
 
-  @Test(expectedExceptions = NullPointerException.class)
+  @Test
   public void resourceBytesFileNotFound() {
     final String shortFileName = "GettysburgAddress.txt";
-    getResourceBytes(shortFileName + "123");
+    try { getResourceBytes(shortFileName + "123"); }
+    catch (IllegalArgumentException e) { //OK
+    }
   }
 
   @Test


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to