Skip to content

Commit 5527ad0

Browse files
committed
Catch NullPointerException for getDeclaredMethod calls
1 parent e4973fc commit 5527ad0

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

dd-java-agent/instrumentation/spark/src/main/java/datadog/trace/instrumentation/spark/AbstractSparkPlanSerializer.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ protected Object safeParseObjectToJson(Object value, int depth) {
127127
}
128128
}
129129
return list;
130-
} else if (value instanceof Partitioning) {
130+
} else if (Partitioning.class.isInstance(value)) {
131131
if (value instanceof TreeNode && depth < MAX_DEPTH) {
132132
HashMap<String, Object> inner = new HashMap<>();
133133
inner.put(
@@ -153,11 +153,15 @@ private String getSimpleString(TreeNode value) {
153153
.getDeclaredMethod("simpleString", new Class[] {int.class})
154154
.invoke(value, MAX_LENGTH)
155155
.toString();
156-
} catch (NoSuchMethodException | IllegalAccessException | InvocationTargetException exception) {
156+
} catch (NullPointerException
157+
| NoSuchMethodException
158+
| IllegalAccessException
159+
| InvocationTargetException exception) {
157160
try {
158161
// Attempt the Spark v2 `simpleString` signature
159162
return TreeNode.class.getDeclaredMethod("simpleString").invoke(value).toString();
160-
} catch (NoSuchMethodException
163+
} catch (NullPointerException
164+
| NoSuchMethodException
161165
| IllegalAccessException
162166
| InvocationTargetException innerException) {
163167
}

0 commit comments

Comments
 (0)