This is an automated email from the ASF dual-hosted git repository.
jamesbognar pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/juneau.git
The following commit(s) were added to refs/heads/master by this push:
new dbd7fd72e2 SonarQube bug fixes
dbd7fd72e2 is described below
commit dbd7fd72e2764da6c6aee2cd495b8587905af158
Author: James Bognar <[email protected]>
AuthorDate: Wed Feb 18 15:37:57 2026 -0500
SonarQube bug fixes
---
.../juneau/commons/function/ResettableSupplier_Test.java | 16 ++++++++++++----
.../org/apache/juneau/commons/utils/FileUtils_Test.java | 16 ++++++----------
2 files changed, 18 insertions(+), 14 deletions(-)
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/function/ResettableSupplier_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/function/ResettableSupplier_Test.java
index 39bcfd5bd2..773e7ef216 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/function/ResettableSupplier_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/function/ResettableSupplier_Test.java
@@ -119,11 +119,15 @@ class ResettableSupplier_Test extends TestBase {
assertEquals(1, callCount.get());
}
- @Test void a06_threadSafety_raceCondition() throws InterruptedException
{
+ @Test
+ @SuppressWarnings({
+ "java:S2925" // Thread.sleep intentional - simulate work to
provoke race condition
+ })
+ void a06_threadSafety_raceCondition() throws InterruptedException {
var callCount = new AtomicInteger();
ResettableSupplier<String> supplier = new
ResettableSupplier<>(() -> {
callCount.incrementAndGet();
- // Simulate some work
+ // Simulate some work to increase chance of race
condition
try {
Thread.sleep(10);
} catch (InterruptedException e) {
@@ -163,7 +167,11 @@ class ResettableSupplier_Test extends TestBase {
assertTrue(callCount.get() >= 1);
}
- @Test void a07_resetAndGetConcurrently() throws InterruptedException {
+ @Test
+ @SuppressWarnings({
+ "java:S2925" // Thread.sleep intentional - timing variance for
concurrency race test
+ })
+ void a07_resetAndGetConcurrently() throws InterruptedException {
var callCount = new AtomicInteger();
ResettableSupplier<Integer> supplier = new
ResettableSupplier<>(() -> {
callCount.incrementAndGet();
@@ -174,7 +182,7 @@ class ResettableSupplier_Test extends TestBase {
for (int i = 0; i < 10; i++) {
supplier.reset();
try {
- Thread.sleep(5); // Increased sleep to
increase chance of race
+ Thread.sleep(5); // Timing variance to
increase chance of race
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/FileUtils_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/FileUtils_Test.java
index 3c7b7fe487..bf85aa14c2 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/FileUtils_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/FileUtils_Test.java
@@ -510,13 +510,11 @@ class FileUtils_Test extends TestBase {
// modifyTimestamp(File)
//====================================================================================================
@Test
- void a057_modifyTimestamp() throws IOException, InterruptedException {
+ void a057_modifyTimestamp() throws IOException {
var f = new File(tempDir.toFile(), "test.txt");
f.createNewFile();
- var originalTime = f.lastModified();
-
- // Wait a bit to ensure time difference
- Thread.sleep(10);
+ var originalTime = System.currentTimeMillis() - 2000;
+ f.setLastModified(originalTime);
FileUtils.modifyTimestamp(f);
var newTime = f.lastModified();
@@ -534,13 +532,11 @@ class FileUtils_Test extends TestBase {
}
@Test
- void a059_modifyTimestamp_directory() throws InterruptedException {
+ void a059_modifyTimestamp_directory() {
var dir = new File(tempDir.toFile(), "testdir");
dir.mkdirs();
- var originalTime = dir.lastModified();
-
- // Wait a bit to ensure time difference
- Thread.sleep(10);
+ var originalTime = System.currentTimeMillis() - 2000;
+ dir.setLastModified(originalTime);
FileUtils.modifyTimestamp(dir);
var newTime = dir.lastModified();