Skip to content

Commit f14c124

Browse files
jbachorikclaude
andcommitted
Improve J9JavacoreParser robustness and completeness
Code review fixes: - Extract relative address from native stack frames ([lib+0xoffset]) - Add safe integer parsing for PID to handle malformed javacores Matches HotspotCrashLogParser patterns for consistency. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 80a7d59 commit f14c124

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

dd-java-agent/agent-crashtracking/src/main/java/datadog/crashtracking/parsers/J9JavacoreParser.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,12 +265,24 @@ public CrashLog parse(String uuid, String javacoreContent) {
265265
ErrorData error =
266266
new ErrorData(kind, message, new StackTrace(enrichedFrames.toArray(new StackFrame[0])));
267267
Metadata metadata = new Metadata("dd-trace-java", VersionInfo.VERSION, "java", null);
268-
ProcInfo procInfo = pid != null ? new ProcInfo(Integer.parseInt(pid)) : null;
268+
Integer parsedPid = safelyParseInt(pid);
269+
ProcInfo procInfo = parsedPid != null ? new ProcInfo(parsedPid) : null;
269270

270271
return new CrashLog(
271272
uuid, incomplete, datetime, error, metadata, OSInfo.current(), procInfo, sigInfo, "1.0");
272273
}
273274

275+
private static Integer safelyParseInt(String value) {
276+
if (value == null) {
277+
return null;
278+
}
279+
try {
280+
return Integer.parseInt(value);
281+
} catch (NumberFormatException e) {
282+
return null;
283+
}
284+
}
285+
274286
private static Section detectSection(String line) {
275287
if (line.contains(SECTION_TITLE)) {
276288
return Section.TITLE;
@@ -374,6 +386,7 @@ private StackFrame parseNativeStackFrame(String frameText) {
374386
String text = frameText.trim();
375387
String function = null;
376388
String file = null;
389+
String relAddress = null;
377390

378391
// Try to extract library from [lib+offset] pattern
379392
int bracketStart = text.indexOf('[');
@@ -383,6 +396,7 @@ private StackFrame parseNativeStackFrame(String frameText) {
383396
int plusIdx = libInfo.indexOf('+');
384397
if (plusIdx > 0) {
385398
file = libInfo.substring(0, plusIdx);
399+
relAddress = libInfo.substring(plusIdx + 1);
386400
} else {
387401
file = libInfo;
388402
}
@@ -423,7 +437,7 @@ private StackFrame parseNativeStackFrame(String frameText) {
423437
}
424438
}
425439

426-
return new StackFrame(file, null, function, null, null, null, null);
440+
return new StackFrame(file, null, function, null, null, null, relAddress);
427441
}
428442

429443
private String parseDateTime(String datePart, String timePart) {

0 commit comments

Comments
 (0)