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 4a990c45dd SonarQube bug fixes
4a990c45dd is described below
commit 4a990c45ddf82f080b794bea77c6f7d6121e4f94
Author: James Bognar <[email protected]>
AuthorDate: Wed Feb 4 16:44:17 2026 -0500
SonarQube bug fixes
---
.../apache/juneau/commons/lang/HashCode_Test.java | 4 +-
.../apache/juneau/commons/lang/Version_Test.java | 20 ++++++----
.../commons/reflect/ConstructorInfo_Test.java | 3 +-
.../commons/reflect/ExecutableInfo_Test.java | 3 +-
.../juneau/commons/reflect/FieldInfo_Test.java | 3 +-
.../juneau/commons/reflect/MethodInfo_Test.java | 3 +-
.../juneau/commons/reflect/PackageInfo_Test.java | 17 ++++----
.../juneau/commons/reflect/ParameterInfo_Test.java | 3 +-
.../juneau/commons/utils/ThrowableUtils_Test.java | 46 ++++++++++------------
.../apache/juneau/commons/utils/Utils_Test.java | 3 +-
10 files changed, 48 insertions(+), 57 deletions(-)
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/lang/HashCode_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/lang/HashCode_Test.java
index 702d00bfbf..f1d506e158 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/lang/HashCode_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/lang/HashCode_Test.java
@@ -440,7 +440,7 @@ class HashCode_Test extends TestBase {
hc.add(i);
}
// Just verify it doesn't throw and produces a value
- assertNotNull(hc.get());
+ assertDoesNotThrow(() -> hc.get());
}
@Test
@@ -464,8 +464,6 @@ class HashCode_Test extends TestBase {
// Different array types should produce different hashcodes
(usually, but not guaranteed)
// Arrays.hashCode for int[] and long[] with same values might
coincidentally be the same
// So we just verify both produce valid hashcodes
- assertNotNull(hc1.get());
- assertNotNull(hc2.get());
// Verify they use Arrays.hashCode correctly
assertEquals(31 * 1 + Arrays.hashCode(new int[] {1, 2, 3}),
hc1.get());
assertEquals(31 * 1 + Arrays.hashCode(new long[] {1L, 2L, 3L}),
hc2.get());
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/lang/Version_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/lang/Version_Test.java
index f8ad730e77..938407e23f 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/lang/Version_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/lang/Version_Test.java
@@ -237,8 +237,10 @@ class Version_Test extends TestBase {
var v2 = of("1.2.4");
// Different versions may have same hashcode (collision), but
usually different
// We just verify both produce valid hashcodes
- assertNotNull(v1.hashCode());
- assertNotNull(v2.hashCode());
+ assertDoesNotThrow(() -> {
+ v1.hashCode();
+ v2.hashCode();
+ });
}
@Test
@@ -258,8 +260,10 @@ class Version_Test extends TestBase {
// These are equal according to equals(Version), so should have
same hashcode
// But hashCode uses Arrays.hashCode which considers length, so
they may differ
// We just verify both produce valid hashcodes
- assertNotNull(v1.hashCode());
- assertNotNull(v2.hashCode());
+ assertDoesNotThrow(() -> {
+ v1.hashCode();
+ v2.hashCode();
+ });
}
@Test
@@ -282,9 +286,11 @@ class Version_Test extends TestBase {
var v2 = of("2.3.4");
var v3 = of("3.4.5");
// All should produce valid hashcodes
- assertNotNull(v1.hashCode());
- assertNotNull(v2.hashCode());
- assertNotNull(v3.hashCode());
+ assertDoesNotThrow(() -> {
+ v1.hashCode();
+ v2.hashCode();
+ v3.hashCode();
+ });
}
@Test
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ConstructorInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ConstructorInfo_Test.java
index 90bd22353f..8e02888ccb 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ConstructorInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ConstructorInfo_Test.java
@@ -524,8 +524,7 @@ class ConstructorInfo_Test extends TestBase {
assertTrue(privateAfter || !privateBefore, "After
setAccessible(), isAccessible() should return true (Java 9+) or false (Java
8)");
// Public constructors might already be accessible
- var publicAccessible = bc1.isAccessible();
- assertNotNull(publicAccessible);
+ assertDoesNotThrow(() -> bc1.isAccessible());
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ExecutableInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ExecutableInfo_Test.java
index 31ae3cf23c..04e8a28d84 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ExecutableInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ExecutableInfo_Test.java
@@ -718,8 +718,7 @@ class ExecutableInfo_Test extends TestBase {
assertTrue(defaultAfter || !defaultBefore, "After
setAccessible(), isAccessible() should return true (Java 9+) or false (Java
8)");
// Public methods might already be accessible
- var publicAccessible = f_isPublic.isAccessible();
- assertNotNull(publicAccessible);
+ assertDoesNotThrow(() -> f_isPublic.isAccessible());
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/FieldInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/FieldInfo_Test.java
index 4273877e6b..d525bf7741 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/FieldInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/FieldInfo_Test.java
@@ -501,8 +501,7 @@ class FieldInfo_Test extends TestBase {
assertTrue(defaultAfter || !defaultBefore, "After
setAccessible(), isAccessible() should return true (Java 9+) or false (Java
8)");
// Public fields might already be accessible
- var publicAccessible = d_isPublic.isAccessible();
- assertNotNull(publicAccessible);
+ assertDoesNotThrow(() -> d_isPublic.isAccessible());
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/MethodInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/MethodInfo_Test.java
index 2d344a1e8d..89c8f37dd9 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/MethodInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/MethodInfo_Test.java
@@ -570,9 +570,8 @@ class MethodInfo_Test extends TestBase {
// So e_a2(int, int) with args (int.class) should return true
because both int parameters match int.class.
// However, the current implementation may have different
behavior - test reflects actual behavior.
// This test case demonstrates the limitation mentioned in the
javadoc.
- var result = e_a2.hasOnlyParameterTypes(int.class);
+ assertDoesNotThrow(() -> e_a2.hasOnlyParameterTypes(int.class));
// The result depends on the implementation - it may be true
(lenient) or false (strict)
- assertNotNull(result);
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/PackageInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/PackageInfo_Test.java
index ccaeb75faf..d7aade8187 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/PackageInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/PackageInfo_Test.java
@@ -234,12 +234,11 @@ class PackageInfo_Test extends TestBase {
var specVersion = pi.getSpecificationVersion();
if (specVersion != null && !specVersion.isEmpty()) {
// Line 309: normal return path when package has a
version
- var compatible = pi.isCompatibleWith("1.0");
- assertNotNull(compatible);
-
- // Test with another version
- var compatible2 = pi.isCompatibleWith("2.0");
- assertNotNull(compatible2);
+ assertDoesNotThrow(() -> {
+ pi.isCompatibleWith("1.0");
+ // Test with another version
+ pi.isCompatibleWith("2.0");
+ });
} else {
// Package doesn't have a version - isCompatibleWith
will throw NumberFormatException
// Line 309 is still executed, exception is thrown from
inner.isCompatibleWith
@@ -261,9 +260,8 @@ class PackageInfo_Test extends TestBase {
@Test
void a016_isSealed() {
var pi = PackageInfo.of(TestClass1.class);
- var sealed = pi.isSealed();
+ assertDoesNotThrow(() -> pi.isSealed());
// Most packages are not sealed
- assertNotNull(sealed);
}
//====================================================================================================
@@ -273,9 +271,8 @@ class PackageInfo_Test extends TestBase {
void a017_isSealed_withUrl() throws Exception {
var pi = PackageInfo.of(TestClass1.class);
var url = new URL("file:///test.jar");
- var sealed = pi.isSealed(url);
+ assertDoesNotThrow(() -> pi.isSealed(url));
// Most packages are not sealed with respect to a specific URL
- assertNotNull(sealed);
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ParameterInfo_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ParameterInfo_Test.java
index f3f92b6804..1599dc674d 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ParameterInfo_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/reflect/ParameterInfo_Test.java
@@ -795,8 +795,7 @@ class ParameterInfo_Test extends TestBase {
@Test
void a024_isNamePresent() {
// This checks if name is present in bytecode, not if it has a
resolved name
- var namePresent = b_a1_a.isNamePresent();
- assertNotNull(namePresent);
+ assertDoesNotThrow(() -> b_a1_a.isNamePresent());
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ThrowableUtils_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ThrowableUtils_Test.java
index d6aa71427c..a3e8211500 100644
---
a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ThrowableUtils_Test.java
+++
b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/ThrowableUtils_Test.java
@@ -228,35 +228,31 @@ class ThrowableUtils_Test extends TestBase {
var ex2 = new RuntimeException("test");
// Same exception type and stack trace should produce same hash
- int hash1 = hash(ex1, null);
- int hash2 = hash(ex2, null);
- // Note: hash might be different due to different stack traces,
but should be consistent
- assertNotNull(hash1);
- assertNotNull(hash2);
-
- // Test with stop class - covers line 180 (break when stopClass
matches)
- // Use a class name that will be in the stack trace
- String testClassName = ThrowableUtils_Test.class.getName();
- int hash3 = hash(ex1, testClassName);
- assertNotNull(hash3);
-
- // Test with stop class that doesn't match (should process all
stack frames)
- int hash4 = hash(ex1, "java.lang.Object");
- assertNotNull(hash4);
-
- // Test with nested exception
- var cause = new IOException("cause");
- var wrapped = new RuntimeException("wrapped", cause);
- int hash5 = hash(wrapped, null);
- assertNotNull(hash5);
+ assertDoesNotThrow(() -> {
+ int hash1 = hash(ex1, null);
+ int hash2 = hash(ex2, null);
+ // Note: hash might be different due to different stack
traces, but should be consistent
+
+ // Test with stop class - covers line 180 (break when
stopClass matches)
+ // Use a class name that will be in the stack trace
+ String testClassName =
ThrowableUtils_Test.class.getName();
+ int hash3 = hash(ex1, testClassName);
+
+ // Test with stop class that doesn't match (should
process all stack frames)
+ int hash4 = hash(ex1, "java.lang.Object");
+
+ // Test with nested exception
+ var cause = new IOException("cause");
+ var wrapped = new RuntimeException("wrapped", cause);
+ int hash5 = hash(wrapped, null);
+
+ // Test with stop class matching a class in the cause
chain - covers line 180
+ int hash7 = hash(wrapped, "java.io.IOException");
+ });
// Test with null exception
int hash6 = hash(null, null);
assertEquals(0, hash6);
-
- // Test with stop class matching a class in the cause chain -
covers line 180
- int hash7 = hash(wrapped, "java.io.IOException");
- assertNotNull(hash7);
}
//====================================================================================================
diff --git
a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/Utils_Test.java
b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/Utils_Test.java
index f15dc7d0cd..10449d24f4 100644
--- a/juneau-utest/src/test/java/org/apache/juneau/commons/utils/Utils_Test.java
+++ b/juneau-utest/src/test/java/org/apache/juneau/commons/utils/Utils_Test.java
@@ -458,8 +458,7 @@ class Utils_Test extends TestBase {
@TestAnnotation("test")
class T {}
var a1 = T.class.getAnnotation(TestAnnotation.class);
- var hash4 = h(a1, "value");
- assertNotNull(hash4);
+ assertDoesNotThrow(() -> h(a1, "value"));
}
//====================================================================================================