Skip to content

Commit a5591ef

Browse files
committed
[java] fixed events without parameters #13109
1 parent 16c335f commit a5591ef

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

java/src/org/openqa/selenium/bidi/ConverterFunctions.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,14 @@ public static <X> Function<JsonInput, X> map(final String keyName, Type typeOfX)
4949
return value;
5050
};
5151
}
52+
53+
public static Function<JsonInput, Void> empty() {
54+
return input -> {
55+
// expects an empty object
56+
input.beginObject();
57+
input.endObject();
58+
59+
return null;
60+
};
61+
}
5262
}

java/src/org/openqa/selenium/devtools/CdpClientGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -437,8 +437,9 @@ public BodyDeclaration<?> toMethodDeclaration() {
437437
.get()
438438
.addStatement(
439439
String.format(
440-
"return new Event<>(\"%s.%s\", input -> null);", domain.name, name));
441-
} else if (type instanceof ObjectType) {
440+
"return new Event<>(\"%s.%s\", input -> ConverterFunctions.empty());",
441+
domain.name, name));
442+
} else if (type instanceof ObjectType || type instanceof ArrayType) {
442443
methodDecl
443444
.getBody()
444445
.get()
@@ -659,7 +660,7 @@ public MethodDeclaration toMethodDeclaration() {
659660
body.addStatement(
660661
String.format(
661662
"return new Command<>(\"%s.%s\", Map.copyOf(params));", domain.name, name));
662-
} else if (type instanceof ObjectType) {
663+
} else if (type instanceof ObjectType || type instanceof ArrayType) {
663664
body.addStatement(
664665
String.format(
665666
"return new Command<>(\"%s.%s\", Map.copyOf(params), input -> %s);",

java/src/org/openqa/selenium/devtools/Connection.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -299,12 +299,14 @@ private void handle(CharSequence data) {
299299
// TODO: This is grossly inefficient. I apologise, and we should fix this.
300300
try (StringReader reader = new StringReader(asString);
301301
JsonInput input = JSON.newInput(reader)) {
302-
Object value = null;
302+
boolean hasParams = false;
303+
Object params = null;
303304
input.beginObject();
304305
while (input.hasNext()) {
305306
switch (input.nextName()) {
306307
case "params":
307-
value = event.getKey().getMapper().apply(input);
308+
hasParams = true;
309+
params = event.getKey().getMapper().apply(input);
308310
break;
309311

310312
default:
@@ -314,21 +316,22 @@ private void handle(CharSequence data) {
314316
}
315317
input.endObject();
316318

317-
if (value == null) {
318-
// Do nothing.
319+
if (!hasParams) {
320+
LOG.fine(
321+
"suppressed event '"
322+
+ event.getKey().getMethod()
323+
+ "', no params in input");
319324
return;
320325
}
321326

322-
final Object finalValue = value;
323-
324327
for (Consumer<?> action : event.getValue()) {
325328
@SuppressWarnings("unchecked")
326329
Consumer<Object> obj = (Consumer<Object>) action;
327330
LOG.log(
328331
getDebugLogLevel(),
329332
"Calling callback for {0} using {1} being passed {2}",
330-
new Object[] {event.getKey(), obj, finalValue});
331-
obj.accept(finalValue);
333+
new Object[] {event.getKey(), obj, params});
334+
obj.accept(params);
332335
}
333336
}
334337
});

0 commit comments

Comments
 (0)