Skip to content

Commit 926a38e

Browse files
committed
OSInfo: re-interrupt thread in 3 catch clauses that swallow InterruptedException
Fixes SonarQube java:S2142 reported on isAndroidTermux, getHardwareName, and resolveArmArchType. Each affected catch now calls Thread.currentThread().interrupt() to restore the interrupt flag instead of silently swallowing it. Documented as deviation #5 from the vendored xerial/sqlite-jdbc source.
1 parent e545435 commit 926a38e

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

src/main/java/net/ladenthin/llama/OSInfo.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@
3737
// org.codehaus.mojo:animal-sniffer-annotations. The standard
3838
// marker has no explanation field; the original strings are
3939
// preserved as adjacent // comments.
40+
// 5. Three catch clauses that swallow InterruptedException
41+
// (isAndroidTermux, getHardwareName, and resolveArmArchType)
42+
// re-interrupt the current thread via
43+
// Thread.currentThread().interrupt() before returning, restoring
44+
// the thread's interrupt flag (SonarQube java:S2142). Upstream
45+
// silently swallows the interrupt.
4046
// The original Apache-2.0 copyright header from the upstream file is
4147
// preserved verbatim below.
4248

@@ -185,6 +191,9 @@ public static boolean isAndroidRuntime() {
185191
public static boolean isAndroidTermux() {
186192
try {
187193
return processRunner.runAndWaitFor("uname -o").toLowerCase().contains("android");
194+
} catch (InterruptedException e) {
195+
Thread.currentThread().interrupt();
196+
return false;
188197
} catch (Exception ignored) {
189198
return false;
190199
}
@@ -229,6 +238,9 @@ static String getHardwareName() {
229238
try {
230239
return processRunner.runAndWaitFor("uname -m");
231240
} catch (Throwable e) {
241+
if (e instanceof InterruptedException) {
242+
Thread.currentThread().interrupt();
243+
}
232244
LogHolder.logger.error("Error while running uname -m", e);
233245
return "unknown";
234246
}
@@ -301,6 +313,9 @@ static String resolveArmArchType() {
301313
}
302314
} catch (IOException | InterruptedException e) {
303315
// ignored: fall back to "arm" arch (soft-float ABI)
316+
if (e instanceof InterruptedException) {
317+
Thread.currentThread().interrupt();
318+
}
304319
}
305320
}
306321
// Use armv5, soft-float ABI

0 commit comments

Comments
 (0)