Skip to content

Commit 691236b

Browse files
authored
[java] specify nullability in package org.openqa.selenium.bidi.script (#17062)
specify nullability in package `org.openqa.selenium.bidi.script`
1 parent 678f21c commit 691236b

25 files changed

Lines changed: 279 additions & 249 deletions

‎java/src/org/openqa/selenium/bidi/browsingcontext/HistoryUpdated.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public static HistoryUpdated fromJson(JsonInput input) {
4747
break;
4848

4949
case "timestamp":
50-
timestamp = input.read(long.class);
50+
timestamp = input.read(Long.class);
5151
break;
5252

5353
case "url":

‎java/src/org/openqa/selenium/bidi/permissions/PermissionState.java‎

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,11 @@
1717

1818
package org.openqa.selenium.bidi.permissions;
1919

20-
import org.jspecify.annotations.NullMarked;
21-
import org.jspecify.annotations.Nullable;
22-
23-
@NullMarked
20+
/**
21+
* @see <a
22+
* href="https://www.w3.org/TR/permissions/#webdriver-bidi-type-permissions-PermissionState">BiDi
23+
* spec</a>
24+
*/
2425
public enum PermissionState {
2526
GRANTED("granted"),
2627
DENIED("denied"),
@@ -37,14 +38,12 @@ public String toString() {
3738
return state;
3839
}
3940

40-
public static @Nullable PermissionState findByName(String name) {
41-
PermissionState result = null;
41+
public static PermissionState findByName(String name) {
4242
for (PermissionState state : values()) {
4343
if (state.toString().equalsIgnoreCase(name)) {
44-
result = state;
45-
break;
44+
return state;
4645
}
4746
}
48-
return result;
47+
throw new IllegalArgumentException("Unsupported permission state: " + name);
4948
}
5049
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Licensed to the Software Freedom Conservancy (SFC) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The SFC licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
@NullMarked
19+
package org.openqa.selenium.bidi.permissions;
20+
21+
import org.jspecify.annotations.NullMarked;

‎java/src/org/openqa/selenium/bidi/script/ArrayLocalValue.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
import java.util.List;
2121
import java.util.Map;
2222

23+
/**
24+
* @see <a href="https://www.w3.org/TR/webdriver-bidi/#cddl-type-scriptarraylocalvalue">BiDi
25+
* spec</a>
26+
*/
2327
public class ArrayLocalValue extends LocalValue {
2428

2529
private final List<LocalValue> value;

‎java/src/org/openqa/selenium/bidi/script/CallFunctionParameters.java‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
import java.util.List;
2222
import java.util.Map;
2323

24+
/**
25+
* @see <a href="https://www.w3.org/TR/webdriver-bidi/#cddl-type-scriptcallfunctionparameters">BiDi
26+
* spec</a>
27+
*/
2428
public class CallFunctionParameters {
2529

2630
private final Map<String, Object> map = new HashMap<>();

‎java/src/org/openqa/selenium/bidi/script/ChannelValue.java‎

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,43 +17,43 @@
1717

1818
package org.openqa.selenium.bidi.script;
1919

20-
import java.util.Collections;
2120
import java.util.Map;
2221
import java.util.TreeMap;
22+
import org.jspecify.annotations.Nullable;
2323

24+
/**
25+
* @see <a href="https://www.w3.org/TR/webdriver-bidi/#type-script-ChannelValue">BiDi spec</a>
26+
*/
2427
public class ChannelValue extends LocalValue {
2528

2629
private final String channelId;
27-
private SerializationOptions options;
28-
29-
private ResultOwnership resultOwnership;
30+
private final @Nullable SerializationOptions options;
31+
private final @Nullable ResultOwnership resultOwnership;
3032

3133
public ChannelValue(String channelId) {
32-
this.channelId = channelId;
34+
this(channelId, null, null);
3335
}
3436

3537
public ChannelValue(String channelId, SerializationOptions options) {
36-
this.channelId = channelId;
37-
this.options = options;
38+
this(channelId, options, null);
3839
}
3940

4041
public ChannelValue(String channelId, ResultOwnership resultOwnership) {
41-
this.channelId = channelId;
42-
this.resultOwnership = resultOwnership;
42+
this(channelId, null, resultOwnership);
4343
}
4444

45-
ChannelValue(String channelId, SerializationOptions options, ResultOwnership resultOwnership) {
45+
ChannelValue(
46+
String channelId,
47+
@Nullable SerializationOptions options,
48+
@Nullable ResultOwnership resultOwnership) {
4649
this.channelId = channelId;
4750
this.options = options;
4851
this.resultOwnership = resultOwnership;
4952
}
5053

5154
@Override
5255
public Map<String, Object> toJson() {
53-
Map<String, Object> toReturn = new TreeMap<>();
54-
5556
Map<String, Object> channelProperties = new TreeMap<>();
56-
5757
channelProperties.put("channel", channelId);
5858

5959
if (options != null) {
@@ -64,9 +64,6 @@ public Map<String, Object> toJson() {
6464
channelProperties.put("ownership", resultOwnership);
6565
}
6666

67-
toReturn.put("type", "channel");
68-
toReturn.put("value", channelProperties);
69-
70-
return Collections.unmodifiableMap(toReturn);
67+
return Map.of("type", "channel", "value", channelProperties);
7168
}
7269
}

‎java/src/org/openqa/selenium/bidi/script/ExceptionDetails.java‎

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@
1717

1818
package org.openqa.selenium.bidi.script;
1919

20-
import static java.util.Collections.unmodifiableMap;
21-
22-
import java.util.Map;
23-
import java.util.TreeMap;
20+
import org.openqa.selenium.internal.Require;
2421
import org.openqa.selenium.json.JsonInput;
2522

2623
public class ExceptionDetails {
@@ -55,15 +52,15 @@ public static ExceptionDetails fromJson(JsonInput input) {
5552
while (input.hasNext()) {
5653
switch (input.nextName()) {
5754
case "columnNumber":
58-
columnNumber = input.read(Long.class);
55+
columnNumber = input.readNonNull(Long.class);
5956
break;
6057

6158
case "exception":
6259
exception = input.read(RemoteValue.class);
6360
break;
6461

6562
case "lineNumber":
66-
lineNumber = input.read(Long.class);
63+
lineNumber = input.readNonNull(Long.class);
6764
break;
6865

6966
case "stackTrace":
@@ -82,7 +79,12 @@ public static ExceptionDetails fromJson(JsonInput input) {
8279

8380
input.endObject();
8481

85-
return new ExceptionDetails(columnNumber, exception, lineNumber, stackTrace, text);
82+
return new ExceptionDetails(
83+
columnNumber,
84+
Require.nonNull("exception", exception),
85+
lineNumber,
86+
Require.nonNull("stackTrace", stackTrace),
87+
Require.nonNull("text", text));
8688
}
8789

8890
public long getColumnNumber() {
@@ -104,15 +106,4 @@ public StackTrace getStacktrace() {
104106
public String getText() {
105107
return this.text;
106108
}
107-
108-
private Map<String, Object> toJson() {
109-
Map<String, Object> toReturn = new TreeMap<>();
110-
toReturn.put("columnNumber", this.columnNumber);
111-
toReturn.put("exception", this.exception);
112-
toReturn.put("lineNumber", this.lineNumber);
113-
toReturn.put("stacktrace", this.stacktrace);
114-
toReturn.put("text", this.text);
115-
116-
return unmodifiableMap(toReturn);
117-
}
118109
}

0 commit comments

Comments
 (0)