Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.file.Files;
import org.jspecify.annotations.NullMarked;

@NullMarked
public class LinuxEphemeralPortRangeDetector implements EphemeralPortRangeDetector {

private final int firstEphemeralPort;
Expand Down
29 changes: 18 additions & 11 deletions java/src/org/openqa/selenium/net/NetworkUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,21 @@
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;
import org.jspecify.annotations.NullMarked;
import org.jspecify.annotations.Nullable;
import org.openqa.selenium.Platform;
import org.openqa.selenium.WebDriverException;
import org.openqa.selenium.internal.Require;

@NullMarked
public class NetworkUtils {

private static InetAddress cachedIp4NonLoopbackAddressOfThisMachine;
private static String cachedIp4NonLoopbackAddressHostName;
private static @Nullable InetAddress cachedIp4NonLoopbackAddressOfThisMachine;
private static @Nullable String cachedIp4NonLoopbackAddressHostName;

private final NetworkInterfaceProvider networkInterfaceProvider;
private volatile String hostname;
private volatile String address;
private volatile @Nullable String hostname;
private volatile @Nullable String address;

NetworkUtils(NetworkInterfaceProvider networkInterfaceProvider) {
this.networkInterfaceProvider = networkInterfaceProvider;
Expand All @@ -56,13 +60,13 @@ public NetworkUtils() {
public String getHostname() {
determineHostnameAndAddress();

return hostname;
return Require.nonNull("Hostname", hostname);
}

public String getHostAddress() {
determineHostnameAndAddress();

return address;
return Require.nonNull("Address", address);
}

public String getPrivateLocalAddress() {
Expand All @@ -81,7 +85,7 @@ public String getPrivateLocalAddress() {
*
* @return A String representing the host name or non-loopback IP4 address of this machine.
*/
public String getNonLoopbackAddressOfThisMachine() {
public @Nullable String getNonLoopbackAddressOfThisMachine() {
InetAddress ip4NonLoopbackAddressOfThisMachine = getIp4NonLoopbackAddressOfThisMachine();
if (!Objects.equals(
cachedIp4NonLoopbackAddressOfThisMachine, ip4NonLoopbackAddressOfThisMachine)) {
Expand Down Expand Up @@ -113,10 +117,13 @@ public InetAddress getIp4NonLoopbackAddressOfThisMachine() {
*
* @return The address part og such an address
*/
public String obtainLoopbackIp4Address() {
public @Nullable String obtainLoopbackIp4Address() {
final NetworkInterface networkInterface = getLoopBackAndIp4Only();
if (networkInterface != null) {
return networkInterface.getIp4LoopbackOnly().getHostName();
InetAddress loopback = networkInterface.getIp4LoopbackOnly();
if (loopback != null) {
return loopback.getHostName();
}
}

final String ipOfIp4LoopBack = getIpOfLoopBackIp4();
Expand Down Expand Up @@ -156,7 +163,7 @@ private InetAddress grabFirstNetworkAddress() {
return firstAddress;
}

public String getIpOfLoopBackIp4() {
public @Nullable String getIpOfLoopBackIp4() {
for (NetworkInterface iface : networkInterfaceProvider.getNetworkInterfaces()) {
final InetAddress netAddress = iface.getIp4LoopbackOnly();
if (netAddress != null) {
Expand All @@ -166,7 +173,7 @@ public String getIpOfLoopBackIp4() {
return null;
}

private NetworkInterface getLoopBackAndIp4Only() {
private @Nullable NetworkInterface getLoopBackAndIp4Only() {
for (NetworkInterface iface : networkInterfaceProvider.getNetworkInterfaces()) {
if (iface.isIp4AddressBindingOnly() && iface.isLoopBack()) {
return iface;
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/net/PortProber.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@
import java.net.SocketTimeoutException;
import java.util.Random;
import java.util.concurrent.TimeUnit;
import org.jspecify.annotations.NullMarked;
import org.openqa.selenium.Platform;

@NullMarked
public class PortProber {

public static final int HIGHEST_PORT = 65535;
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/net/UrlChecker.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.logging.Logger;
import org.jspecify.annotations.NullMarked;

/** Polls a URL until a HTTP 200 response is received. */
@NullMarked
public class UrlChecker {

private static final Logger LOG = Logger.getLogger(UrlChecker.class.getName());
Expand Down
2 changes: 2 additions & 0 deletions java/src/org/openqa/selenium/net/Urls.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import org.jspecify.annotations.NullMarked;
import org.openqa.selenium.internal.Require;

@NullMarked
public class Urls {

private Urls() {
Expand Down
Loading