diff --git a/java/src/org/openqa/selenium/net/DefaultNetworkInterfaceProvider.java b/java/src/org/openqa/selenium/net/DefaultNetworkInterfaceProvider.java index 389798d5deacd..d47bee5790e19 100644 --- a/java/src/org/openqa/selenium/net/DefaultNetworkInterfaceProvider.java +++ b/java/src/org/openqa/selenium/net/DefaultNetworkInterfaceProvider.java @@ -24,9 +24,12 @@ import java.util.Collections; import java.util.Enumeration; import java.util.List; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Platform; import org.openqa.selenium.WebDriverException; +@NullMarked public class DefaultNetworkInterfaceProvider implements NetworkInterfaceProvider { // Cache the list of interfaces between instances. This is mostly used // to get the loopback interface, so it's ok even though interfaces may go @@ -104,7 +107,7 @@ private String getLocalInterfaceName() { } @Override - public NetworkInterface getLoInterface() { + public @Nullable NetworkInterface getLoInterface() { final String localIF = getLocalInterfaceName(); try { final java.net.NetworkInterface byName = java.net.NetworkInterface.getByName(localIF); diff --git a/java/src/org/openqa/selenium/net/HostIdentifier.java b/java/src/org/openqa/selenium/net/HostIdentifier.java index 1431c236ae499..4be04c1d70b05 100644 --- a/java/src/org/openqa/selenium/net/HostIdentifier.java +++ b/java/src/org/openqa/selenium/net/HostIdentifier.java @@ -27,13 +27,16 @@ import java.util.Enumeration; import java.util.concurrent.TimeUnit; import java.util.logging.Logger; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; import org.openqa.selenium.Platform; +@NullMarked public class HostIdentifier { private static final Logger LOG = Logger.getLogger(HostIdentifier.class.getName()); - private static volatile String hostName; - private static volatile String hostAddress; + private static volatile @Nullable String hostName; + private static volatile @Nullable String hostAddress; private static String resolveHostName() { // Ideally, we'd use InetAddress.getLocalHost, but this does a reverse DNS lookup. On Windows diff --git a/java/src/org/openqa/selenium/net/NetworkInterface.java b/java/src/org/openqa/selenium/net/NetworkInterface.java index 81e9c4c19f675..feb7d647eb9a9 100644 --- a/java/src/org/openqa/selenium/net/NetworkInterface.java +++ b/java/src/org/openqa/selenium/net/NetworkInterface.java @@ -29,14 +29,17 @@ import java.util.logging.Logger; import java.util.stream.Collectors; import java.util.stream.StreamSupport; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; +@NullMarked public class NetworkInterface { private static final Logger LOG = Logger.getLogger(NetworkInterface.class.getName()); private final String name; - private java.net.NetworkInterface networkInterface; + private java.net.@Nullable NetworkInterface networkInterface; private final Iterable inetAddresses; - private Boolean isLoopback; + private @Nullable Boolean isLoopback; public NetworkInterface(java.net.NetworkInterface networkInterface) { this(networkInterface.getName(), list(networkInterface.getInetAddresses())); @@ -82,7 +85,7 @@ private boolean isLoopBackFromINetAddresses(Iterable inetAddresses) return iterator.hasNext() && iterator.next().isLoopbackAddress(); } - InetAddress getIp4LoopbackOnly() { + @Nullable InetAddress getIp4LoopbackOnly() { // Goes by the wildly unscientific assumption that if there are more than one set of // loopback addresses, firefox will bind to the last one we get. // An alternate theory if this fails is that firefox prefers 127.0.0.1 @@ -106,7 +109,7 @@ static boolean isIpv6(InetAddress address) { return address instanceof Inet6Address; } - public InetAddress getIp4NonLoopBackOnly() { + public @Nullable InetAddress getIp4NonLoopBackOnly() { for (InetAddress inetAddress : inetAddresses) { if (!inetAddress.isLoopbackAddress() && !isIpv6(inetAddress)) { return inetAddress; @@ -115,7 +118,7 @@ public InetAddress getIp4NonLoopBackOnly() { return null; } - public InetAddress getIp6Address() { + public @Nullable InetAddress getIp6Address() { for (InetAddress inetAddress : inetAddresses) { if (isIpv6(inetAddress)) { return inetAddress; diff --git a/java/src/org/openqa/selenium/net/NetworkInterfaceProvider.java b/java/src/org/openqa/selenium/net/NetworkInterfaceProvider.java index a426f29bc0495..6bca42489a480 100644 --- a/java/src/org/openqa/selenium/net/NetworkInterfaceProvider.java +++ b/java/src/org/openqa/selenium/net/NetworkInterfaceProvider.java @@ -17,16 +17,20 @@ package org.openqa.selenium.net; +import org.jspecify.annotations.NullMarked; +import org.jspecify.annotations.Nullable; + /** * Provides information about the local network interfaces. * *

Basically an abstraction created to allow stubbing of java.net.NetworkInterface, also soothes * some of the jdk1.2 idioms from this interface into jdk1.5 idioms. */ +@NullMarked public interface NetworkInterfaceProvider { Iterable getNetworkInterfaces(); // TODO: Remove this whole method // This method should only return an interface if it's named exactly "lo" - NetworkInterface getLoInterface(); + @Nullable NetworkInterface getLoInterface(); }