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 @@ -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
Expand Down Expand Up @@ -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);
Expand Down
7 changes: 5 additions & 2 deletions java/src/org/openqa/selenium/net/HostIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 8 additions & 5 deletions java/src/org/openqa/selenium/net/NetworkInterface.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<InetAddress> inetAddresses;
private Boolean isLoopback;
private @Nullable Boolean isLoopback;

public NetworkInterface(java.net.NetworkInterface networkInterface) {
this(networkInterface.getName(), list(networkInterface.getInetAddresses()));
Expand Down Expand Up @@ -82,7 +85,7 @@ private boolean isLoopBackFromINetAddresses(Iterable<InetAddress> 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
Expand All @@ -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;
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
* <p>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<NetworkInterface> getNetworkInterfaces();

// TODO: Remove this whole method
// This method should only return an interface if it's named exactly "lo"
NetworkInterface getLoInterface();
@Nullable NetworkInterface getLoInterface();
}
Loading