Skip to content

Commit 79d8ad5

Browse files
mk868diemol
authored andcommitted
[java] Add nullness for net (SeleniumHQ#15083)
Co-authored-by: Diego Molina <[email protected]>
1 parent da38700 commit 79d8ad5

File tree

4 files changed

+22
-9
lines changed

4 files changed

+22
-9
lines changed

java/src/org/openqa/selenium/net/DefaultNetworkInterfaceProvider.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@
2424
import java.util.Collections;
2525
import java.util.Enumeration;
2626
import java.util.List;
27+
import org.jspecify.annotations.NullMarked;
28+
import org.jspecify.annotations.Nullable;
2729
import org.openqa.selenium.Platform;
2830
import org.openqa.selenium.WebDriverException;
2931

32+
@NullMarked
3033
public class DefaultNetworkInterfaceProvider implements NetworkInterfaceProvider {
3134
// Cache the list of interfaces between instances. This is mostly used
3235
// to get the loopback interface, so it's ok even though interfaces may go
@@ -104,7 +107,7 @@ private String getLocalInterfaceName() {
104107
}
105108

106109
@Override
107-
public NetworkInterface getLoInterface() {
110+
public @Nullable NetworkInterface getLoInterface() {
108111
final String localIF = getLocalInterfaceName();
109112
try {
110113
final java.net.NetworkInterface byName = java.net.NetworkInterface.getByName(localIF);

java/src/org/openqa/selenium/net/HostIdentifier.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,16 @@
2727
import java.util.Enumeration;
2828
import java.util.concurrent.TimeUnit;
2929
import java.util.logging.Logger;
30+
import org.jspecify.annotations.NullMarked;
31+
import org.jspecify.annotations.Nullable;
3032
import org.openqa.selenium.Platform;
3133

34+
@NullMarked
3235
public class HostIdentifier {
3336
private static final Logger LOG = Logger.getLogger(HostIdentifier.class.getName());
3437

35-
private static volatile String hostName;
36-
private static volatile String hostAddress;
38+
private static volatile @Nullable String hostName;
39+
private static volatile @Nullable String hostAddress;
3740

3841
private static String resolveHostName() {
3942
// Ideally, we'd use InetAddress.getLocalHost, but this does a reverse DNS lookup. On Windows

java/src/org/openqa/selenium/net/NetworkInterface.java

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,17 @@
2929
import java.util.logging.Logger;
3030
import java.util.stream.Collectors;
3131
import java.util.stream.StreamSupport;
32+
import org.jspecify.annotations.NullMarked;
33+
import org.jspecify.annotations.Nullable;
3234

35+
@NullMarked
3336
public class NetworkInterface {
3437
private static final Logger LOG = Logger.getLogger(NetworkInterface.class.getName());
3538

3639
private final String name;
37-
private java.net.NetworkInterface networkInterface;
40+
private java.net.@Nullable NetworkInterface networkInterface;
3841
private final Iterable<InetAddress> inetAddresses;
39-
private Boolean isLoopback;
42+
private @Nullable Boolean isLoopback;
4043

4144
public NetworkInterface(java.net.NetworkInterface networkInterface) {
4245
this(networkInterface.getName(), list(networkInterface.getInetAddresses()));
@@ -82,7 +85,7 @@ private boolean isLoopBackFromINetAddresses(Iterable<InetAddress> inetAddresses)
8285
return iterator.hasNext() && iterator.next().isLoopbackAddress();
8386
}
8487

85-
InetAddress getIp4LoopbackOnly() {
88+
@Nullable InetAddress getIp4LoopbackOnly() {
8689
// Goes by the wildly unscientific assumption that if there are more than one set of
8790
// loopback addresses, firefox will bind to the last one we get.
8891
// An alternate theory if this fails is that firefox prefers 127.0.0.1
@@ -106,7 +109,7 @@ static boolean isIpv6(InetAddress address) {
106109
return address instanceof Inet6Address;
107110
}
108111

109-
public InetAddress getIp4NonLoopBackOnly() {
112+
public @Nullable InetAddress getIp4NonLoopBackOnly() {
110113
for (InetAddress inetAddress : inetAddresses) {
111114
if (!inetAddress.isLoopbackAddress() && !isIpv6(inetAddress)) {
112115
return inetAddress;
@@ -115,7 +118,7 @@ public InetAddress getIp4NonLoopBackOnly() {
115118
return null;
116119
}
117120

118-
public InetAddress getIp6Address() {
121+
public @Nullable InetAddress getIp6Address() {
119122
for (InetAddress inetAddress : inetAddresses) {
120123
if (isIpv6(inetAddress)) {
121124
return inetAddress;

java/src/org/openqa/selenium/net/NetworkInterfaceProvider.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,20 @@
1717

1818
package org.openqa.selenium.net;
1919

20+
import org.jspecify.annotations.NullMarked;
21+
import org.jspecify.annotations.Nullable;
22+
2023
/**
2124
* Provides information about the local network interfaces.
2225
*
2326
* <p>Basically an abstraction created to allow stubbing of java.net.NetworkInterface, also soothes
2427
* some of the jdk1.2 idioms from this interface into jdk1.5 idioms.
2528
*/
29+
@NullMarked
2630
public interface NetworkInterfaceProvider {
2731
Iterable<NetworkInterface> getNetworkInterfaces();
2832

2933
// TODO: Remove this whole method
3034
// This method should only return an interface if it's named exactly "lo"
31-
NetworkInterface getLoInterface();
35+
@Nullable NetworkInterface getLoInterface();
3236
}

0 commit comments

Comments
 (0)