Skip to content

Commit 136a3fa

Browse files
committed
fix: Address SonarQube issues in CRaC implementation
- Add proper assertions to TracingUtilsCracTest to fix Blocker issue - Add null check for objectMapper in beforeCheckpoint to fix Critical issue - Maintain singleton pattern for CRaC Resource registration (Info issue acceptable) All tests passing: 28 tests, 0 failures
1 parent fdbb6db commit 136a3fa

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

powertools-tracing/src/main/java/software/amazon/lambda/powertools/tracing/TracingUtils.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,9 @@ public void beforeCheckpoint(Context<? extends Resource> context) throws Excepti
235235
serviceName();
236236

237237
// Initialize ObjectMapper for JSON serialization
238-
objectMapper.writeValueAsString("dummy");
238+
if (objectMapper != null) {
239+
objectMapper.writeValueAsString("dummy");
240+
}
239241
}
240242

241243
@Override

powertools-tracing/src/test/java/software/amazon/lambda/powertools/tracing/TracingUtilsCracTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ void testPrimeMethodDoesNotThrowException() {
3434
@Test
3535
void testTracingUtilsLoadsSuccessfully() {
3636
// Simply calling TracingUtils.prime() should trigger CRaC registration
37-
TracingUtils.prime();
38-
// If we get here without exception, the test passes
37+
assertThatNoException().isThrownBy(() -> TracingUtils.prime());
38+
39+
// Verify that TracingUtils class is loaded and accessible
40+
assertThatNoException().isThrownBy(() -> TracingUtils.objectMapper());
3941
}
4042
}

0 commit comments

Comments
 (0)