Skip to content

Commit c45f58d

Browse files
authored
Merge pull request #250 from apache/fix_some_spotbugs_warnings
Fixed a few SpotBugs Warnings.
2 parents fe21452 + fca6c8c commit c45f58d

File tree

5 files changed

+23
-18
lines changed

5 files changed

+23
-18
lines changed

.github/workflows/auto-jdk-matrix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Auto JDK Matrix Test & Install
22

33
on:
44
push:
5-
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.xml', '**/*.yaml', '**/*.yml', '**/.*', '**/LICENSE', '**/NOTICE' ]
5+
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.yaml', '**/*.yml', '**/LICENSE', '**/NOTICE' ]
66
branches: [ 'main', '[0-9]+.[0-9]+.[Xx]' ]
77
pull_request:
8-
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.xml', '**/*.yaml', '**/*.yml', '**/.*', '**/LICENSE', '**/NOTICE' ]
8+
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.yaml', '**/*.yml', '**/LICENSE', '**/NOTICE' ]
99
# The branches below must be a subset of the branches above
1010
branches: [ 'main', '[0-9]+.[0-9]+.[Xx]' ]
1111
workflow_dispatch:

.github/workflows/auto-os-matrix.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@ name: Auto OS Matrix Test & Install
22

33
on:
44
push:
5-
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.xml', '**/*.yaml', '**/*.yml', '**/.*', '**/LICENSE', '**/NOTICE' ]
5+
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.yaml', '**/*.yml', '**/LICENSE', '**/NOTICE' ]
66
branches: [ 'main', '[0-9]+.[0-9]+.[Xx]' ]
77
pull_request:
8-
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.xml', '**/*.yaml', '**/*.yml', '**/.*', '**/LICENSE', '**/NOTICE' ]
8+
paths-ignore: [ '**/*.html', '**/*.md', '**/*.txt', '**/*.yaml', '**/*.yml', '**/LICENSE', '**/NOTICE' ]
99
# The branches below must be a subset of the branches above
1010
branches: [ 'main', '[0-9]+.[0-9]+.[Xx]' ]
1111
workflow_dispatch:

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ Note: *primitive* := *{byte, short, int, long, float, double}*
6666
* *Memory.map(File, Arena)* (read only)
6767
* *WritableMemory.writableMap(File)*
6868

69-
## Release 5.0.0 (inclusive) to 6.0.0 (exclusive)
69+
## Release 5.0.0 (inclusive) to 7.0.0 (exclusive)
7070
Starting with release *datasketches-memory-5.0.0*, this Memory component supports only Java 21 when compiling from source and may work with later Java versions at runtime.
7171

7272
### Runtime Notes:
@@ -106,7 +106,7 @@ To run javadoc:
106106

107107
mvn clean javadoc:javadoc -DskipTests=true
108108

109-
To run the eclipse plugin on this multi-module project, use:
109+
To run the eclipse plugin on this project, use:
110110

111111
mvn clean eclipse:eclipse -DskipTests=true
112112

src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMapMemoryTest.java

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,48 +43,52 @@ public class AllocateDirectMapMemoryTest {
4343
@Test
4444
public void simpleMap() throws IOException {
4545
File file = UtilTest.setGettysburgAddressFileToReadOnly();
46+
Memory mem = null;
4647
try (Arena arena = Arena.ofConfined()) {
47-
Memory mem = Memory.map(file, arena);
48+
mem = Memory.map(file, arena);
4849
arena.close();
4950
} //The Try-With-Resources will throw since it is already closed
5051
catch (IllegalStateException e) { /* OK */ }
52+
if (mem != null) { assertFalse(mem.isAlive()); }
5153
}
5254

5355
@Test
5456
public void testIllegalArguments() throws IOException {
5557
File file = getResourceFile("GettysburgAddress.txt");
58+
Memory mem = null;
5659
try (Arena arena = Arena.ofConfined()) {
57-
Memory mem = Memory.map(file, -1, Integer.MAX_VALUE, ByteOrder.nativeOrder(), arena);
60+
mem = Memory.map(file, -1, Integer.MAX_VALUE, ByteOrder.nativeOrder(), arena);
5861
fail("Failed: test IllegalArgumentException: Position was negative.");
5962
mem.getCapacity();
6063
}
61-
catch (IllegalArgumentException e) {
62-
//ok
63-
}
64+
catch (IllegalArgumentException e) { /* OK */ }
65+
if (mem != null) { assertFalse(mem.isAlive()); }
6466
try (Arena arena = Arena.ofConfined()) {
65-
Memory mem = Memory.map(file, 0, -1, ByteOrder.nativeOrder(), arena);
66-
fail("Failed: testIllegalArgumentException: Size was negative.");
67-
} catch (IllegalArgumentException e) {
68-
//ok
67+
mem = Memory.map(file, 0, -1, ByteOrder.nativeOrder(), arena);
68+
fail("Failed: test IllegalArgumentException: Size was negative.");
6969
}
70+
catch (IllegalArgumentException e) { /* OK */ }
71+
if (mem != null) { assertFalse(mem.isAlive()); }
7072
}
7173

7274
@Test
7375
public void testMapAndMultipleClose() throws IOException {
7476
File file = getResourceFile("GettysburgAddress.txt");
7577
long memCapacity = file.length();
78+
Memory mem = null;
7679
Memory mem2 = null;
7780
try {
7881
try (Arena arena = Arena.ofConfined()) {
79-
Memory mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder(), arena);
82+
mem = Memory.map(file, 0, memCapacity, ByteOrder.nativeOrder(), arena);
8083
mem2 = mem;
8184
assertEquals(memCapacity, mem.getCapacity());
8285
arena.close();
8386
assertFalse(mem.isAlive());
8487
} //a close inside the TWR block will throw here
8588
}
8689
catch (IllegalStateException e) { /* expected */ }
87-
assertFalse(mem2.isAlive());
90+
if (mem != null) { assertFalse(mem.isAlive()); }
91+
if (mem2 != null) { assertFalse(mem2.isAlive()); }
8892
}
8993

9094
@Test

src/test/java/org/apache/datasketches/memory/internal/AllocateDirectMemoryTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void simpleAllocateDirect() {
5151
assertTrue(wMem.isAlive());
5252
}
5353
//The TWR block has exited, so the memory should be not alive
54-
assertFalse(wMem2.isAlive());
54+
if (wMem2 != null) { assertFalse(wMem2.isAlive()); }
5555
}
5656

5757
@Test
@@ -96,6 +96,7 @@ public void checkExplicitCloseNoTWR() {
9696
Arena arena = Arena.ofConfined();
9797
WritableMemory wmem = WritableMemory.allocateDirect(cap, arena);
9898
arena.close(); //explicit close
99+
assertFalse(wmem.isAlive());
99100
}
100101

101102
@Test

0 commit comments

Comments
 (0)