Skip to content

Commit 21a9ab4

Browse files
dfa1claude
andauthored
chore: clear a batch of Sonar findings (#12)
- Discard unused size_t status from native free() calls and swallowed destructor throwables via unnamed variables `_` instead of `ignored` (S1854 / S1481 / S7467). - Exclude the benchmark module from Sonar analysis: it is a JMH harness, not shipped runtime, and its @Setup/@teardown lifecycle trips a false "resource not closed" report (S2095). - Reword the C-struct reference comments to prose so they are not parsed as commented-out code (S125). - Extract the repeated ZDICT field-name literals into constants (S1192). Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 7c8bb9a commit 21a9ab4

13 files changed

Lines changed: 34 additions & 27 deletions

pom.xml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,13 @@
6363
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
6464
<sonar.organization>dfa11</sonar.organization>
6565
<sonar.projectKey>dfa1_zstd-java</sonar.projectKey>
66-
<!-- The benchmark module is JMH main code with no tests by design, and the
67-
native modules carry no Java sources — neither should drag the coverage
68-
ratio. Exclude from coverage. -->
66+
<!-- The benchmark module is a JMH harness, not shipped runtime: its
67+
@Setup/@TearDown lifecycle trips false "resource not closed" reports and
68+
it has no tests by design. Exclude from analysis entirely (which also
69+
keeps it out of the coverage ratio). -->
70+
<sonar.exclusions>
71+
**/benchmark/**
72+
</sonar.exclusions>
6973
<sonar.coverage.exclusions>
7074
**/benchmark/**
7175
</sonar.coverage.exclusions>

zstd/src/main/java/io/github/dfa1/zstd/Bindings.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ final class Bindings {
166166
static final MethodHandle DPARAM_GET_BOUNDS =
167167
NativeLibrary.lookup("ZSTD_dParam_getBounds", FunctionDescriptor.of(BOUNDS_LAYOUT, JAVA_INT));
168168

169-
// ZSTD_frameProgression { u64 ingested, consumed, produced, flushed; u32 currentJobID, nbActiveWorkers; }
169+
// ZSTD_frameProgression layout: u64 ingested, consumed, produced, flushed, then u32 currentJobID, nbActiveWorkers.
170170
private static final MemoryLayout FRAME_PROGRESSION_LAYOUT =
171171
MemoryLayout.structLayout(JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_INT, JAVA_INT);
172172
// ZSTD_frameProgression ZSTD_getFrameProgression(const ZSTD_CCtx*) — returned by value

zstd/src/main/java/io/github/dfa1/zstd/NativeObject.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public final void close() {
3737
if (!MemorySegment.NULL.equals(p)) {
3838
try {
3939
tryClose(p);
40-
} catch (Throwable ignored) {
40+
} catch (Throwable _) {
4141
// destructors must not throw
4242
}
4343
}

zstd/src/main/java/io/github/dfa1/zstd/ZstdCompressCtx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ public long sizeOf() {
222222

223223
@Override
224224
protected void tryClose(MemorySegment ptr) throws Throwable {
225-
long ignored = (long) Bindings.FREE_CCTX.invokeExact(ptr);
225+
var _ = (long) Bindings.FREE_CCTX.invokeExact(ptr);
226226
}
227227

228228
@SuppressWarnings("unchecked")

zstd/src/main/java/io/github/dfa1/zstd/ZstdCompressDict.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public long sizeOf() {
111111

112112
@Override
113113
protected void tryClose(MemorySegment ptr) throws Throwable {
114-
long ignored = (long) Bindings.FREE_CDICT.invokeExact(ptr);
114+
var _ = (long) Bindings.FREE_CDICT.invokeExact(ptr);
115115
}
116116

117117
@SuppressWarnings("unchecked")

zstd/src/main/java/io/github/dfa1/zstd/ZstdCompressStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public long sizeOf() {
129129
@Override
130130
protected void tryClose(MemorySegment ptr) throws Throwable {
131131
try {
132-
long ignored = (long) Bindings.FREE_CCTX.invokeExact(ptr);
132+
var _ = (long) Bindings.FREE_CCTX.invokeExact(ptr);
133133
} finally {
134134
arena.close();
135135
}

zstd/src/main/java/io/github/dfa1/zstd/ZstdDecompressCtx.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ public long sizeOf() {
182182

183183
@Override
184184
protected void tryClose(MemorySegment ptr) throws Throwable {
185-
long ignored = (long) Bindings.FREE_DCTX.invokeExact(ptr);
185+
var _ = (long) Bindings.FREE_DCTX.invokeExact(ptr);
186186
}
187187

188188
@SuppressWarnings("unchecked")

zstd/src/main/java/io/github/dfa1/zstd/ZstdDecompressDict.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public long sizeOf() {
8181

8282
@Override
8383
protected void tryClose(MemorySegment ptr) throws Throwable {
84-
long ignored = (long) Bindings.FREE_DDICT.invokeExact(ptr);
84+
var _ = (long) Bindings.FREE_DDICT.invokeExact(ptr);
8585
}
8686

8787
@SuppressWarnings("unchecked")

zstd/src/main/java/io/github/dfa1/zstd/ZstdDecompressStream.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public long sizeOf() {
8080
@Override
8181
protected void tryClose(MemorySegment ptr) throws Throwable {
8282
try {
83-
long ignored = (long) Bindings.FREE_DCTX.invokeExact(ptr);
83+
var _ = (long) Bindings.FREE_DCTX.invokeExact(ptr);
8484
} finally {
8585
arena.close();
8686
}

zstd/src/main/java/io/github/dfa1/zstd/ZstdDictionary.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,21 @@
3131
/// }
3232
public final class ZstdDictionary {
3333

34-
// ZDICT_cover_params_t { unsigned k,d,steps,nbThreads; double splitPoint;
35-
// unsigned shrinkDict, shrinkDictMaxRegression; ZDICT_params_t zParams; }
36-
// ZDICT_params_t { int compressionLevel; unsigned notificationLevel, dictID; }
34+
private static final String FIELD_NB_THREADS = "nbThreads";
35+
private static final String FIELD_COMPRESSION_LEVEL = "compressionLevel";
36+
37+
// ZDICT_cover_params_t fields: unsigned k, d, steps, nbThreads; double
38+
// splitPoint; unsigned shrinkDict, shrinkDictMaxRegression; then a nested
39+
// ZDICT_params_t of int compressionLevel, unsigned notificationLevel, dictID.
3740
private static final MemoryLayout COVER_PARAMS = MemoryLayout.structLayout(
3841
JAVA_INT.withName("k"),
3942
JAVA_INT.withName("d"),
4043
JAVA_INT.withName("steps"),
41-
JAVA_INT.withName("nbThreads"),
44+
JAVA_INT.withName(FIELD_NB_THREADS),
4245
JAVA_DOUBLE.withName("splitPoint"),
4346
JAVA_INT.withName("shrinkDict"),
4447
JAVA_INT.withName("shrinkDictMaxRegression"),
45-
JAVA_INT.withName("compressionLevel"),
48+
JAVA_INT.withName(FIELD_COMPRESSION_LEVEL),
4649
JAVA_INT.withName("notificationLevel"),
4750
JAVA_INT.withName("dictID"),
4851
MemoryLayout.paddingLayout(4)); // trailing pad to the C struct's 8-byte alignment
@@ -54,13 +57,13 @@ public final class ZstdDictionary {
5457
JAVA_INT.withName("d"),
5558
JAVA_INT.withName("f"),
5659
JAVA_INT.withName("steps"),
57-
JAVA_INT.withName("nbThreads"),
60+
JAVA_INT.withName(FIELD_NB_THREADS),
5861
MemoryLayout.paddingLayout(4),
5962
JAVA_DOUBLE.withName("splitPoint"),
6063
JAVA_INT.withName("accel"),
6164
JAVA_INT.withName("shrinkDict"),
6265
JAVA_INT.withName("shrinkDictMaxRegression"),
63-
JAVA_INT.withName("compressionLevel"),
66+
JAVA_INT.withName(FIELD_COMPRESSION_LEVEL),
6467
JAVA_INT.withName("notificationLevel"),
6568
JAVA_INT.withName("dictID"));
6669

@@ -192,8 +195,8 @@ private static ZstdDictionary optimize(List<byte[]> samples, int maxDictBytes,
192195
// zeroed params (auto-tune k/d/steps); set single-threaded + target level.
193196
MemoryLayout layout = fast ? FASTCOVER_PARAMS : COVER_PARAMS;
194197
MemorySegment params = arena.allocate(layout);
195-
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement("nbThreads")), 1);
196-
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement("compressionLevel")), compressionLevel);
198+
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement(FIELD_NB_THREADS)), 1);
199+
params.set(JAVA_INT, layout.byteOffset(PathElement.groupElement(FIELD_COMPRESSION_LEVEL)), compressionLevel);
197200
MethodHandle handle = fast ? Bindings.ZDICT_OPTIMIZE_FASTCOVER : Bindings.ZDICT_OPTIMIZE_COVER;
198201
MemorySegment dictBuf = arena.allocate(maxDictBytes);
199202
long produced;

0 commit comments

Comments
 (0)