Skip to content

Commit a75c5b1

Browse files
mk868diemol
authored andcommitted
[java] Add nullness for Proxy and print (SeleniumHQ#15094)
Co-authored-by: Diego Molina <[email protected]>
1 parent bf794a1 commit a75c5b1

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

java/src/org/openqa/selenium/Proxy.java

Lines changed: 24 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626
import java.util.Optional;
2727
import java.util.function.Consumer;
2828
import java.util.stream.Collectors;
29+
import org.jspecify.annotations.NullMarked;
30+
import org.jspecify.annotations.Nullable;
2931

3032
/**
3133
* Configuration parameters for using proxies in WebDriver. Generally you should pass an object of
@@ -34,6 +36,7 @@
3436
* configuration. That is, it is an error to set an <code>httpProxy</code> manually and then turn on
3537
* proxy autodetect.
3638
*/
39+
@NullMarked
3740
public class Proxy {
3841

3942
public enum ProxyType {
@@ -77,15 +80,15 @@ public String toString() {
7780

7881
private ProxyType proxyType = ProxyType.UNSPECIFIED;
7982
private boolean autodetect = false;
80-
private String ftpProxy;
81-
private String httpProxy;
82-
private String noProxy;
83-
private String sslProxy;
84-
private String socksProxy;
85-
private Integer socksVersion;
86-
private String socksUsername;
87-
private String socksPassword;
88-
private String proxyAutoconfigUrl;
83+
private @Nullable String ftpProxy;
84+
private @Nullable String httpProxy;
85+
private @Nullable String noProxy;
86+
private @Nullable String sslProxy;
87+
private @Nullable String socksProxy;
88+
private @Nullable Integer socksVersion;
89+
private @Nullable String socksUsername;
90+
private @Nullable String socksPassword;
91+
private @Nullable String proxyAutoconfigUrl;
8992

9093
public Proxy() {
9194
// Empty default constructor
@@ -120,7 +123,7 @@ public Proxy(Map<String, ?> raw) {
120123
setters.put(AUTODETECT, value -> setAutodetect((Boolean) value));
121124
raw.forEach(
122125
(key, value) -> {
123-
if (key != null && value != null) {
126+
if (key != null && value != null && setters.containsKey(key)) {
124127
setters.get(key).accept(value);
125128
}
126129
});
@@ -223,7 +226,7 @@ public Proxy setAutodetect(boolean autodetect) {
223226
*
224227
* @return the FTP proxy hostname if present, or null if not set
225228
*/
226-
public String getFtpProxy() {
229+
public @Nullable String getFtpProxy() {
227230
return ftpProxy;
228231
}
229232

@@ -245,7 +248,7 @@ public Proxy setFtpProxy(String ftpProxy) {
245248
*
246249
* @return the HTTP proxy hostname if present, or null if not set
247250
*/
248-
public String getHttpProxy() {
251+
public @Nullable String getHttpProxy() {
249252
return httpProxy;
250253
}
251254

@@ -267,7 +270,7 @@ public Proxy setHttpProxy(String httpProxy) {
267270
*
268271
* @return The proxy bypass (noproxy) addresses
269272
*/
270-
public String getNoProxy() {
273+
public @Nullable String getNoProxy() {
271274
return noProxy;
272275
}
273276

@@ -289,7 +292,7 @@ public Proxy setNoProxy(String noProxy) {
289292
*
290293
* @return the SSL tunnel proxy hostname if present, null otherwise
291294
*/
292-
public String getSslProxy() {
295+
public @Nullable String getSslProxy() {
293296
return sslProxy;
294297
}
295298

@@ -311,7 +314,7 @@ public Proxy setSslProxy(String sslProxy) {
311314
*
312315
* @return the SOCKS proxy if present, null otherwise
313316
*/
314-
public String getSocksProxy() {
317+
public @Nullable String getSocksProxy() {
315318
return socksProxy;
316319
}
317320

@@ -333,7 +336,7 @@ public Proxy setSocksProxy(String socksProxy) {
333336
*
334337
* @return the SOCKS version if present, null otherwise
335338
*/
336-
public Integer getSocksVersion() {
339+
public @Nullable Integer getSocksVersion() {
337340
return socksVersion;
338341
}
339342

@@ -355,7 +358,7 @@ public Proxy setSocksVersion(Integer socksVersion) {
355358
*
356359
* @return the SOCKS proxy's username
357360
*/
358-
public String getSocksUsername() {
361+
public @Nullable String getSocksUsername() {
359362
return socksUsername;
360363
}
361364

@@ -377,7 +380,7 @@ public Proxy setSocksUsername(String username) {
377380
*
378381
* @return the SOCKS proxy's password
379382
*/
380-
public String getSocksPassword() {
383+
public @Nullable String getSocksPassword() {
381384
return socksPassword;
382385
}
383386

@@ -399,7 +402,7 @@ public Proxy setSocksPassword(String password) {
399402
*
400403
* @return the proxy auto-configuration URL
401404
*/
402-
public String getProxyAutoconfigUrl() {
405+
public @Nullable String getProxyAutoconfigUrl() {
403406
return proxyAutoconfigUrl;
404407
}
405408

@@ -428,7 +431,7 @@ private void verifyProxyTypeCompatibility(ProxyType compatibleProxy) {
428431
}
429432

430433
@SuppressWarnings({"unchecked"})
431-
public static Proxy extractFrom(Capabilities capabilities) {
434+
public static @Nullable Proxy extractFrom(Capabilities capabilities) {
432435
Object rawProxy = capabilities.getCapability("proxy");
433436
Proxy proxy = null;
434437
if (rawProxy != null) {
@@ -472,7 +475,7 @@ public String toString() {
472475
}
473476

474477
@Override
475-
public boolean equals(Object o) {
478+
public boolean equals(@Nullable Object o) {
476479
if (this == o) {
477480
return true;
478481
}

java/src/org/openqa/selenium/print/PageMargin.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import org.jspecify.annotations.NullMarked;
2223

24+
@NullMarked
2325
public class PageMargin {
2426
private final double top;
2527
private final double bottom;

java/src/org/openqa/selenium/print/PageSize.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@
1919

2020
import java.util.HashMap;
2121
import java.util.Map;
22+
import org.jspecify.annotations.NullMarked;
2223

24+
@NullMarked
2325
public class PageSize {
2426

2527
private final double height;

java/src/org/openqa/selenium/print/PrintOptions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,11 @@
2020
import java.util.HashMap;
2121
import java.util.List;
2222
import java.util.Map;
23+
import org.jspecify.annotations.NullMarked;
24+
import org.jspecify.annotations.Nullable;
2325
import org.openqa.selenium.internal.Require;
2426

27+
@NullMarked
2528
public class PrintOptions {
2629

2730
public enum Orientation {
@@ -46,7 +49,7 @@ public String toString() {
4649
private boolean shrinkToFit = true;
4750
private PageSize pageSize = new PageSize();
4851
private PageMargin pageMargin = new PageMargin();
49-
private String[] pageRanges;
52+
private String @Nullable [] pageRanges;
5053

5154
public Orientation getOrientation() {
5255
return this.orientation;
@@ -56,7 +59,7 @@ public void setOrientation(Orientation orientation) {
5659
this.orientation = Require.nonNull("orientation", orientation);
5760
}
5861

59-
public String[] getPageRanges() {
62+
public String @Nullable [] getPageRanges() {
6063
return this.pageRanges;
6164
}
6265

0 commit comments

Comments
 (0)