AlexanderSaydakov commented on code in PR #250:
URL: 
https://github.com/apache/datasketches-memory/pull/250#discussion_r1932714269


##########
src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java:
##########
@@ -43,48 +43,52 @@ public class AllocateDirectMapMemoryTest {
   @Test
   public void simpleMap() throws IOException {
     File file = UtilTest.setGettysburgAddressFileToReadOnly();
+    Memory mem = null;
     try (Arena arena = Arena.ofConfined()) {
-      Memory mem = Memory.map(file, arena);
+      mem = Memory.map(file, arena);
       arena.close();
     } //The Try-With-Resources will throw since it is already closed
     catch (IllegalStateException e) { /* OK */ }
+    assertFalse(mem.isAlive());
   }
 
   @Test
   public void testIllegalArguments() throws IOException {
     File file = getResourceFile("GettysburgAddress.txt");
+    Memory mem = null;
     try (Arena arena = Arena.ofConfined()) {
-      Memory mem = Memory.map(file, -1, Integer.MAX_VALUE, 
ByteOrder.nativeOrder(), arena);
+      mem = Memory.map(file, -1, Integer.MAX_VALUE, ByteOrder.nativeOrder(), 
arena);
       fail("Failed: test IllegalArgumentException: Position was negative.");
       mem.getCapacity();
     }
-    catch (IllegalArgumentException e) {
-      //ok
-    }
+    catch (IllegalArgumentException e) { /* OK */ }
+    if (mem != null) { assertFalse(mem.isAlive()); }
     try (Arena arena = Arena.ofConfined()) {
-      Memory mem = Memory.map(file, 0, -1, ByteOrder.nativeOrder(), arena);
-      fail("Failed: testIllegalArgumentException: Size was negative.");
-    } catch (IllegalArgumentException e) {
-      //ok
+      mem = Memory.map(file, 0, -1, ByteOrder.nativeOrder(), arena);
+      fail("Failed: test IllegalArgumentException: Size was negative.");
     }
+    catch (IllegalArgumentException e) { /* OK */ }
+    if (mem != null) { assertFalse(mem.isAlive()); }
   }
 
   @Test
   public void testMapAndMultipleClose() throws IOException {
     File file = getResourceFile("GettysburgAddress.txt");
     long memCapacity = file.length();
+    Memory mem = null;
     Memory mem2 = null;
     try {
       try (Arena arena = Arena.ofConfined()) {
-        Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder(), 
arena);
+        mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder(), arena);
         mem2 = mem;
         assertEquals(memCapacity, mem.getCapacity());
         arena.close();
         assertFalse(mem.isAlive());
       } //a close inside the TWR block will throw here
     }
     catch (IllegalStateException e) { /* expected */ }
-    assertFalse(mem2.isAlive());
+    assertFalse(mem.isAlive());

Review Comment:
   mem can be null



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


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

Reply via email to