Remove forbidden suppressions for InetSocketAddress

This commit is contained in:
Ryan Ernst 2015-12-11 18:20:09 -08:00
parent 7cbb955d19
commit a0c69fe7f9
3 changed files with 8 additions and 13 deletions

View File

@ -105,6 +105,7 @@ import org.elasticsearch.watcher.ResourceWatcherService;
import java.io.BufferedWriter; import java.io.BufferedWriter;
import java.io.IOException; import java.io.IOException;
import java.net.Inet6Address; import java.net.Inet6Address;
import java.net.InetAddress;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.CopyOption; import java.nio.file.CopyOption;
@ -453,13 +454,12 @@ public class Node implements Releasable {
Path tmpPortsFile = environment.logsFile().resolve(type + ".ports.tmp"); Path tmpPortsFile = environment.logsFile().resolve(type + ".ports.tmp");
try (BufferedWriter writer = Files.newBufferedWriter(tmpPortsFile, Charset.forName("UTF-8"))) { try (BufferedWriter writer = Files.newBufferedWriter(tmpPortsFile, Charset.forName("UTF-8"))) {
for (TransportAddress address : boundAddress.boundAddresses()) { for (TransportAddress address : boundAddress.boundAddresses()) {
InetSocketAddress socketAddress = buildAddress(address.getAddress(), address.getPort()); InetAddress inetAddress = InetAddress.getByName(address.getAddress());
if (socketAddress.getAddress() instanceof Inet6Address && if (inetAddress instanceof Inet6Address && inetAddress.isLinkLocalAddress()) {
socketAddress.getAddress().isLinkLocalAddress()) {
// no link local, just causes problems // no link local, just causes problems
continue; continue;
} }
writer.write(NetworkAddress.formatAddress(socketAddress) + "\n"); writer.write(NetworkAddress.formatAddress(new InetSocketAddress(inetAddress, address.getPort())) + "\n");
} }
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException("Failed to write ports file", e); throw new RuntimeException("Failed to write ports file", e);
@ -471,9 +471,4 @@ public class Node implements Releasable {
throw new RuntimeException("Failed to rename ports file", e); throw new RuntimeException("Failed to rename ports file", e);
} }
} }
@SuppressForbidden(reason = "Need to specify address and port")
private static InetSocketAddress buildAddress(String address, int port) {
return new InetSocketAddress(address, port);
}
} }

View File

@ -107,14 +107,14 @@ public abstract class ESSmokeClientTestCase extends LuceneTestCase {
return client; return client;
} }
@SuppressForbidden(reason = "Must use port when creating address")
private static Client startClient() throws IOException { private static Client startClient() throws IOException {
String[] stringAddresses = clusterAddresses.split(","); String[] stringAddresses = clusterAddresses.split(",");
TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length]; TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length];
int i = 0; int i = 0;
for (String stringAddress : stringAddresses) { for (String stringAddress : stringAddresses) {
URL url = new URL("http://" + stringAddress); URL url = new URL("http://" + stringAddress);
transportAddresses[i++] = new InetSocketTransportAddress(new InetSocketAddress(url.getHost(), url.getPort())); InetAddress inetAddress = InetAddress.getByName(url.getHost());
transportAddresses[i++] = new InetSocketTransportAddress(new InetSocketAddress(inetAddress, url.getPort()));
} }
return startClient(createTempDir(), transportAddresses); return startClient(createTempDir(), transportAddresses);
} }

View File

@ -1730,14 +1730,14 @@ public abstract class ESIntegTestCase extends ESTestCase {
return Settings.EMPTY; return Settings.EMPTY;
} }
@SuppressForbidden(reason = "Must use port when creating address")
private ExternalTestCluster buildExternalCluster(String clusterAddresses) throws IOException { private ExternalTestCluster buildExternalCluster(String clusterAddresses) throws IOException {
String[] stringAddresses = clusterAddresses.split(","); String[] stringAddresses = clusterAddresses.split(",");
TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length]; TransportAddress[] transportAddresses = new TransportAddress[stringAddresses.length];
int i = 0; int i = 0;
for (String stringAddress : stringAddresses) { for (String stringAddress : stringAddresses) {
URL url = new URL("http://" + stringAddress); URL url = new URL("http://" + stringAddress);
transportAddresses[i++] = new InetSocketTransportAddress(new InetSocketAddress(url.getHost(), url.getPort())); InetAddress inetAddress = InetAddress.getByName(url.getHost());
transportAddresses[i++] = new InetSocketTransportAddress(new InetSocketAddress(inetAddress, url.getPort()));
} }
return new ExternalTestCluster(createTempDir(), externalClusterClientSettings(), transportClientPlugins(), transportAddresses); return new ExternalTestCluster(createTempDir(), externalClusterClientSettings(), transportClientPlugins(), transportAddresses);
} }