Skip to content

Commit 843cb89

Browse files
authored
Merge branch 'trunk' into java-websocket-port-bidi
2 parents 2b91cd4 + 540f916 commit 843cb89

25 files changed

+543
-452
lines changed

java/src/org/openqa/selenium/By.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,7 @@ public String toString() {
296296

297297
public static class ByClassName extends PreW3CLocator {
298298

299+
private static final Pattern AT_LEAST_ONE_WHITESPACE = Pattern.compile(".*\\s.*");
299300
private final String className;
300301

301302
public ByClassName(String className) {
@@ -305,7 +306,7 @@ public ByClassName(String className) {
305306
.nonNull("Cannot find elements when the class name expression is null."),
306307
".%s");
307308

308-
if (className.matches(".*\\s.*")) {
309+
if (AT_LEAST_ONE_WHITESPACE.matcher(className).matches()) {
309310
throw new InvalidSelectorException("Compound class names not permitted");
310311
}
311312

java/src/org/openqa/selenium/Platform.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -369,6 +369,7 @@ public String toString() {
369369
}
370370
};
371371

372+
private static final Pattern VERSION_PATTERN = Pattern.compile("^(\\d+)\\.(\\d+).*");
372373
private static @Nullable Platform current;
373374
private final String[] partOfOsName;
374375
private int minorVersion = 0;
@@ -389,21 +390,20 @@ public static Platform getCurrent() {
389390

390391
String version = System.getProperty("os.version", "0.0.0");
391392
int major = 0;
392-
int min = 0;
393+
int minor = 0;
393394

394-
Pattern pattern = Pattern.compile("^(\\d+)\\.(\\d+).*");
395-
Matcher matcher = pattern.matcher(version);
395+
final Matcher matcher = VERSION_PATTERN.matcher(version);
396396
if (matcher.matches()) {
397397
try {
398398
major = Integer.parseInt(matcher.group(1));
399-
min = Integer.parseInt(matcher.group(2));
399+
minor = Integer.parseInt(matcher.group(2));
400400
} catch (NumberFormatException e) {
401401
// These things happen
402402
}
403403
}
404404

405405
current.majorVersion = major;
406-
current.minorVersion = min;
406+
current.minorVersion = minor;
407407
}
408408
return current;
409409
}

java/src/org/openqa/selenium/Point.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121
import org.jspecify.annotations.NullMarked;
2222
import org.jspecify.annotations.Nullable;
2323

24-
/** A copy of java.awt.Point, to remove dependency on awt. */
24+
/** Represents a point in a two-dimensional space with x and y coordinates. */
2525
@NullMarked
2626
public class Point {
27-
public int x;
28-
public int y;
27+
public final int x;
28+
public final int y;
2929

3030
public Point(int x, int y) {
3131
this.x = x;

java/src/org/openqa/selenium/chrome/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ java_export(
2020
"//java/src/org/openqa/selenium/json",
2121
"//java/src/org/openqa/selenium/manager",
2222
"//java/src/org/openqa/selenium/remote",
23+
"@maven//:org_jspecify_jspecify",
2324
],
2425
)

java/src/org/openqa/selenium/chrome/ChromeDriverService.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.util.List;
3232
import java.util.Locale;
3333
import java.util.Map;
34+
import org.jspecify.annotations.Nullable;
3435
import org.openqa.selenium.Capabilities;
3536
import org.openqa.selenium.WebDriverException;
3637
import org.openqa.selenium.chromium.ChromiumDriverLogLevel;
@@ -102,11 +103,11 @@ public class ChromeDriverService extends DriverService {
102103
* @throws IOException If an I/O error occurs.
103104
*/
104105
public ChromeDriverService(
105-
File executable,
106+
@Nullable File executable,
106107
int port,
107-
Duration timeout,
108-
List<String> args,
109-
Map<String, String> environment)
108+
@Nullable Duration timeout,
109+
@Nullable List<String> args,
110+
@Nullable Map<String, String> environment)
110111
throws IOException {
111112
super(
112113
executable,
@@ -151,13 +152,13 @@ public static ChromeDriverService createDefaultService() {
151152
public static class Builder
152153
extends DriverService.Builder<ChromeDriverService, ChromeDriverService.Builder> {
153154

154-
private Boolean disableBuildCheck;
155-
private Boolean readableTimestamp;
156-
private Boolean appendLog;
157-
private Boolean verbose;
158-
private Boolean silent;
159-
private String allowedListIps;
160-
private ChromiumDriverLogLevel logLevel;
155+
private @Nullable Boolean disableBuildCheck;
156+
private @Nullable Boolean readableTimestamp;
157+
private @Nullable Boolean appendLog;
158+
private @Nullable Boolean verbose;
159+
private @Nullable Boolean silent;
160+
private @Nullable String allowedListIps;
161+
private @Nullable ChromiumDriverLogLevel logLevel;
161162

162163
@Override
163164
public int score(Capabilities capabilities) {
@@ -202,7 +203,7 @@ public Builder withBuildCheckDisabled(boolean noBuildCheck) {
202203
* @param logLevel {@link ChromiumDriverLogLevel} for desired log level output.
203204
* @return A self reference.
204205
*/
205-
public Builder withLogLevel(ChromiumDriverLogLevel logLevel) {
206+
public Builder withLogLevel(@Nullable ChromiumDriverLogLevel logLevel) {
206207
this.logLevel = logLevel;
207208
this.silent = false;
208209
this.verbose = false;
@@ -244,7 +245,7 @@ public Builder withVerbose(boolean verbose) {
244245
* @param allowedListIps Comma-separated list of remote IPv4 addresses.
245246
* @return A self reference.
246247
*/
247-
public Builder withAllowedListIps(String allowedListIps) {
248+
public Builder withAllowedListIps(@Nullable String allowedListIps) {
248249
this.allowedListIps = allowedListIps;
249250
return this;
250251
}
@@ -255,7 +256,7 @@ public Builder withAllowedListIps(String allowedListIps) {
255256
* @param readableTimestamp Whether the timestamp of the log is readable.
256257
* @return A self reference.
257258
*/
258-
public Builder withReadableTimestamp(Boolean readableTimestamp) {
259+
public Builder withReadableTimestamp(@Nullable Boolean readableTimestamp) {
259260
this.readableTimestamp = readableTimestamp;
260261
return this;
261262
}
@@ -321,7 +322,11 @@ protected List<String> createArgs() {
321322

322323
@Override
323324
protected ChromeDriverService createDriverService(
324-
File exe, int port, Duration timeout, List<String> args, Map<String, String> environment) {
325+
@Nullable File exe,
326+
int port,
327+
@Nullable Duration timeout,
328+
@Nullable List<String> args,
329+
@Nullable Map<String, String> environment) {
325330
try {
326331
return new ChromeDriverService(exe, port, timeout, args, environment);
327332
} catch (IOException e) {

java/src/org/openqa/selenium/firefox/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ java_export(
1616
"//java/src/org/openqa/selenium/json",
1717
"//java/src/org/openqa/selenium/manager",
1818
"//java/src/org/openqa/selenium/remote",
19+
"@maven//:org_jspecify_jspecify",
1920
],
2021
)

java/src/org/openqa/selenium/firefox/FirefoxDriverService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import java.time.Duration;
2323
import java.util.List;
2424
import java.util.Map;
25+
import org.jspecify.annotations.Nullable;
2526
import org.openqa.selenium.remote.service.DriverService;
2627

2728
public abstract class FirefoxDriverService extends DriverService {
@@ -35,11 +36,11 @@ public abstract class FirefoxDriverService extends DriverService {
3536
* @throws IOException If an I/O error occurs.
3637
*/
3738
public FirefoxDriverService(
38-
File executable,
39+
@Nullable File executable,
3940
int port,
40-
Duration timeout,
41-
List<String> args,
42-
Map<String, String> environment)
41+
@Nullable Duration timeout,
42+
@Nullable List<String> args,
43+
@Nullable Map<String, String> environment)
4344
throws IOException {
4445
super(executable, port, timeout, args, environment);
4546
}

java/src/org/openqa/selenium/firefox/GeckoDriverService.java

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import java.util.List;
3333
import java.util.Locale;
3434
import java.util.Map;
35+
import org.jspecify.annotations.Nullable;
3536
import org.openqa.selenium.Capabilities;
3637
import org.openqa.selenium.WebDriverException;
3738
import org.openqa.selenium.net.PortProber;
@@ -83,11 +84,11 @@ public class GeckoDriverService extends FirefoxDriverService {
8384
* @throws IOException If an I/O error occurs.
8485
*/
8586
public GeckoDriverService(
86-
File executable,
87+
@Nullable File executable,
8788
int port,
88-
Duration timeout,
89-
List<String> args,
90-
Map<String, String> environment)
89+
@Nullable Duration timeout,
90+
@Nullable List<String> args,
91+
@Nullable Map<String, String> environment)
9192
throws IOException {
9293
super(
9394
executable,
@@ -142,10 +143,10 @@ protected boolean hasShutdownEndpoint() {
142143
public static class Builder
143144
extends FirefoxDriverService.Builder<GeckoDriverService, GeckoDriverService.Builder> {
144145

145-
private String allowHosts;
146-
private FirefoxDriverLogLevel logLevel;
147-
private Boolean logTruncate;
148-
private File profileRoot;
146+
private @Nullable String allowHosts;
147+
private @Nullable FirefoxDriverLogLevel logLevel;
148+
private @Nullable Boolean logTruncate;
149+
private @Nullable File profileRoot;
149150

150151
@Override
151152
public int score(Capabilities capabilities) {
@@ -168,7 +169,7 @@ public int score(Capabilities capabilities) {
168169
* @param allowHosts Space-separated list of host names.
169170
* @return A self reference.
170171
*/
171-
public Builder withAllowHosts(String allowHosts) {
172+
public Builder withAllowHosts(@Nullable String allowHosts) {
172173
this.allowHosts = allowHosts;
173174
return this;
174175
}
@@ -177,7 +178,7 @@ public Builder withAllowHosts(String allowHosts) {
177178
* @param logLevel which log events to record.
178179
* @return A self reference.
179180
*/
180-
public Builder withLogLevel(FirefoxDriverLogLevel logLevel) {
181+
public Builder withLogLevel(@Nullable FirefoxDriverLogLevel logLevel) {
181182
this.logLevel = logLevel;
182183
return this;
183184
}
@@ -187,7 +188,7 @@ public Builder withLogLevel(FirefoxDriverLogLevel logLevel) {
187188
* default; setting "false" removes truncation
188189
* @return A self reference.
189190
*/
190-
public Builder withTruncatedLogs(Boolean truncate) {
191+
public Builder withTruncatedLogs(@Nullable Boolean truncate) {
191192
this.logTruncate = truncate;
192193
return this;
193194
}
@@ -198,7 +199,7 @@ public Builder withTruncatedLogs(Boolean truncate) {
198199
* @param root location to store temporary profiles Defaults to the system temporary directory.
199200
* @return A self reference.
200201
*/
201-
public GeckoDriverService.Builder withProfileRoot(File root) {
202+
public GeckoDriverService.Builder withProfileRoot(@Nullable File root) {
202203
this.profileRoot = root;
203204
return this;
204205
}
@@ -270,7 +271,11 @@ protected List<String> createArgs() {
270271

271272
@Override
272273
protected GeckoDriverService createDriverService(
273-
File exe, int port, Duration timeout, List<String> args, Map<String, String> environment) {
274+
@Nullable File exe,
275+
int port,
276+
@Nullable Duration timeout,
277+
@Nullable List<String> args,
278+
@Nullable Map<String, String> environment) {
274279
try {
275280
return new GeckoDriverService(exe, port, timeout, args, environment);
276281
} catch (IOException e) {

java/src/org/openqa/selenium/grid/commands/InfoCommand.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import java.nio.charset.StandardCharsets;
3232
import java.util.Collections;
3333
import java.util.Set;
34+
import java.util.regex.Pattern;
3435
import org.openqa.selenium.cli.CliCommand;
3536
import org.openqa.selenium.cli.WrappedPrintWriter;
3637
import org.openqa.selenium.grid.config.Role;
@@ -39,6 +40,8 @@
3940
@AutoService(CliCommand.class)
4041
public class InfoCommand implements CliCommand {
4142

43+
private static final Pattern CODE_OR_LIST_PATTERN = Pattern.compile("^\\s*(\\*|\\d+\\.).*");
44+
4245
public String getName() {
4346
return "info";
4447
}
@@ -109,7 +112,7 @@ public Executable configure(PrintStream out, PrintStream err, String... args) {
109112
break;
110113
}
111114

112-
String path = getClass().getPackage().getName().replaceAll("\\.", "/") + "/" + toDisplay;
115+
String path = getClass().getPackage().getName().replace('.', '/') + "/" + toDisplay;
113116
String content;
114117
try {
115118
content = readContent(path);
@@ -143,11 +146,11 @@ private String readContent(String path) throws IOException {
143146
} else if ("```".equals(line)) {
144147
inCode = !inCode;
145148
} else {
146-
if (line.startsWith("=")) {
149+
if (line.charAt(0) == '=') {
147150
formattedText.append("\n");
148151
}
149152
formattedText.append(line);
150-
if (inCode || line.matches("^\\s*\\*.*") || line.matches("^\\s*\\d+\\..*")) {
153+
if (inCode || CODE_OR_LIST_PATTERN.matcher(line).matches()) {
151154
formattedText.append("\n");
152155
} else {
153156
formattedText.append(" ");

java/src/org/openqa/selenium/grid/node/docker/DockerOptions.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,10 @@ public class DockerOptions {
6868
private static final String DEFAULT_DOCKER_NETWORK = "bridge";
6969
private static final Logger LOG = Logger.getLogger(DockerOptions.class.getName());
7070
private static final Json JSON = new Json();
71+
private static final Pattern LINUX_DEVICE_MAPPING_WITH_DEFAULT_PERMISSIONS =
72+
Pattern.compile("^([\\w/-]+):([\\w/-]+)$");
73+
private static final Pattern LINUX_DEVICE_MAPPING_WITH_PERMISSIONS =
74+
Pattern.compile("^([\\w/-]+):([\\w/-]+):(\\w+)$");
7175
private final Config config;
7276

7377
public DockerOptions(Config config) {
@@ -209,23 +213,17 @@ public Map<Capabilities, Collection<SessionFactory>> getDockerSessionFactories(
209213
}
210214

211215
protected List<Device> getDevicesMapping() {
212-
Pattern linuxDeviceMappingWithDefaultPermissionsPattern =
213-
Pattern.compile("^([\\w\\/-]+):([\\w\\/-]+)$");
214-
Pattern linuxDeviceMappingWithPermissionsPattern =
215-
Pattern.compile("^([\\w\\/-]+):([\\w\\/-]+):([\\w]+)$");
216-
217216
List<String> devices =
218217
config.getAll(DOCKER_SECTION, "devices").orElseGet(Collections::emptyList);
219218

220219
List<Device> deviceMapping = new ArrayList<>();
221220
for (String device : devices) {
222221
String deviceMappingDefined = device.trim();
223-
Matcher matcher =
224-
linuxDeviceMappingWithDefaultPermissionsPattern.matcher(deviceMappingDefined);
222+
Matcher matcher = LINUX_DEVICE_MAPPING_WITH_DEFAULT_PERMISSIONS.matcher(deviceMappingDefined);
225223

226224
if (matcher.matches()) {
227225
deviceMapping.add(device(matcher.group(1), matcher.group(2), null));
228-
} else if ((matcher = linuxDeviceMappingWithPermissionsPattern.matcher(deviceMappingDefined))
226+
} else if ((matcher = LINUX_DEVICE_MAPPING_WITH_PERMISSIONS.matcher(deviceMappingDefined))
229227
.matches()) {
230228
deviceMapping.add(device(matcher.group(1), matcher.group(2), matcher.group(3)));
231229
}

0 commit comments

Comments
 (0)