Skip to content

Commit 59b0330

Browse files
jpbempeldevflow.devflow-routing-intake
andauthored
Fix NullPointerException in Exception Replay (#12429)
Fix NullPointerException in Exception Replay For FastThrow, getStackTrace can return null instead of empty StackTraceElement array call only once getStackTrace fix possible NPE from chained exceptions Co-authored-by: devflow.devflow-routing-intake <devflow.devflow-routing-intake@kubernetes.us1.ddbuild.io>
1 parent a4b447e commit 59b0330

2 files changed

Lines changed: 7 additions & 3 deletions

File tree

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/AbstractExceptionDebugger.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,12 @@ public void handleException(Throwable t, AgentSpan span) {
9393
Throwable throwable;
9494
int chainedExceptionIdx = 0;
9595
while ((throwable = chainedExceptions.pollFirst()) != null) {
96+
StackTraceElement[] stackTrace = throwable.getStackTrace();
97+
if (stackTrace == null || stackTrace.length == 0) {
98+
continue;
99+
}
96100
ExceptionProbeManager.CreationResult creationResult =
97-
exceptionProbeManager.createProbesForException(
98-
throwable.getStackTrace(), chainedExceptionIdx);
101+
exceptionProbeManager.createProbesForException(stackTrace, chainedExceptionIdx);
99102
if (creationResult.probesCreated > 0) {
100103
if (!applyConfigAsync) {
101104
applyExceptionConfiguration(fingerprint);

dd-java-agent/agent-debugger/src/main/java/com/datadog/debugger/exception/DefaultExceptionDebugger.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@ protected boolean shouldHandleException(Throwable t, AgentSpan span) {
5454
}
5555
// do not handle exception with no stacktrace. cannot capture anything for it.
5656
// includes also FastThrow ones
57-
if (t.getStackTrace().length == 0) {
57+
StackTraceElement[] stackTrace = t.getStackTrace();
58+
if (stackTrace == null || stackTrace.length == 0) {
5859
return false;
5960
}
6061
return circuitBreaker.trip();

0 commit comments

Comments
 (0)