Skip to content

Commit 07dfc77

Browse files
BorisOsipovdiemol
andauthored
[java] Handle null parameters in TracedCommandExecutor (#10081)
Co-authored-by: Diego Molina <[email protected]>
1 parent 5dd24d2 commit 07dfc77

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

java/src/org/openqa/selenium/remote/TracedCommandExecutor.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222

2323
import java.io.IOException;
2424
import java.util.Map;
25+
import java.util.Objects;
2526

2627
public class TracedCommandExecutor implements CommandExecutor {
2728

@@ -44,7 +45,7 @@ public Response execute(Command command) throws IOException {
4445
Map<String, ?> parameters = command.getParameters();
4546
if (parameters != null && parameters.size() > 0) {
4647
for (Map.Entry<String, ?> parameter : parameters.entrySet()) {
47-
commandSpan.setAttribute("parameter." + parameter.getKey(), parameter.getValue().toString());
48+
commandSpan.setAttribute("parameter." + parameter.getKey(), Objects.toString(parameter.getValue(), "null"));
4849
}
4950
}
5051
return delegate.execute(command);

java/test/org/openqa/selenium/remote/TracedCommandExecutorTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,22 @@ public void canCreateSpanWithAllAttributes() throws IOException {
7676
verifyNoMoreInteractions(span);
7777
}
7878

79+
@Test
80+
public void canCreateSpanFromNullParameter() throws IOException {
81+
SessionId sessionId = new SessionId(UUID.randomUUID());
82+
Map<String, Object> parameters = new HashMap<>();
83+
parameters.put("param1", null);
84+
Command command = new Command(sessionId, "findElement", parameters);
85+
86+
tracedCommandExecutor.execute(command);
87+
88+
verify(span, times(1)).setAttribute("sessionId", sessionId.toString());
89+
verify(span, times(1)).setAttribute("command", "findElement");
90+
verify(span, times(1)).setAttribute("parameter.param1", "null");
91+
verify(span, times(1)).close();
92+
verifyNoMoreInteractions(span);
93+
}
94+
7995
@Test
8096
public void canCreateSpanWithSessionIdAndCommandName() throws IOException {
8197
SessionId sessionId = new SessionId(UUID.randomUUID());

0 commit comments

Comments
 (0)