From 6db90da25e9c5c918116102662915b87cc464aec Mon Sep 17 00:00:00 2001 From: javanna Date: Fri, 10 Jun 2016 11:40:13 +0200 Subject: [PATCH] [TEST] Remove usage of @SuppressForbidden due to sun HttpServer usage, resolve some violations that were hidden by it --- client-sniffer/build.gradle | 3 +++ .../org/elasticsearch/client/sniff/HostsSnifferTests.java | 8 +++----- client/build.gradle | 3 +++ .../org/elasticsearch/client/RestClientIntegTests.java | 8 +++----- 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/client-sniffer/build.gradle b/client-sniffer/build.gradle index af04d85ac61..a8e4b684bf6 100644 --- a/client-sniffer/build.gradle +++ b/client-sniffer/build.gradle @@ -54,6 +54,9 @@ forbiddenApisMain { } forbiddenApisTest { + //we are excluding jdk-non-portable to allow for com.sun.net.httpserver.* usage + //TODO remove this line once https://github.com/policeman-tools/forbidden-apis/issues/103 gets solved + bundledSignatures = ['jdk-unsafe', 'jdk-deprecated', 'jdk-system-out'] //client does not depend on core, so only jdk signatures should be checked signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')] } diff --git a/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java b/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java index af1b878cfd4..06f8fd6940e 100644 --- a/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java +++ b/client-sniffer/src/test/java/org/elasticsearch/client/sniff/HostsSnifferTests.java @@ -31,7 +31,6 @@ import org.apache.http.Consts; import org.apache.http.HttpHost; import org.apache.http.client.methods.HttpGet; import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.SuppressForbidden; import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; @@ -42,6 +41,7 @@ import org.junit.Before; import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URISyntaxException; import java.util.ArrayList; @@ -57,7 +57,6 @@ import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.equalTo; @IgnoreJRERequirement -@SuppressForbidden(reason = "uses sun HttpServer") public class HostsSnifferTests extends LuceneTestCase { private int sniffRequestTimeout; @@ -84,7 +83,7 @@ public class HostsSnifferTests extends LuceneTestCase { } public void testSniffNodes() throws IOException, URISyntaxException { - HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostName(), httpServer.getAddress().getPort()); + HttpHost httpHost = new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort()); try (RestClient restClient = RestClient.builder(httpHost).build()) { HostsSniffer sniffer = new HostsSniffer(restClient, sniffRequestTimeout, scheme); try { @@ -114,13 +113,12 @@ public class HostsSnifferTests extends LuceneTestCase { } private static HttpServer createHttpServer(final SniffResponse sniffResponse, final int sniffTimeoutMillis) throws IOException { - HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0); + HttpServer httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0); httpServer.createContext("/_nodes/http", new ResponseHandler(sniffTimeoutMillis, sniffResponse)); return httpServer; } @IgnoreJRERequirement - @SuppressForbidden(reason = "uses sun HttpServer") private static class ResponseHandler implements HttpHandler { private final int sniffTimeoutMillis; private final SniffResponse sniffResponse; diff --git a/client/build.gradle b/client/build.gradle index f905114fd0f..c2479b31d1e 100644 --- a/client/build.gradle +++ b/client/build.gradle @@ -52,6 +52,9 @@ forbiddenApisMain { } forbiddenApisTest { + //we are excluding jdk-non-portable to allow for com.sun.net.httpserver.* usage + //TODO remove this line once https://github.com/policeman-tools/forbidden-apis/issues/103 gets solved + bundledSignatures = ['jdk-unsafe', 'jdk-deprecated', 'jdk-system-out'] //client does not depend on core, so only jdk signatures should be checked signaturesURLs = [PrecommitTasks.getResource('/forbidden/jdk-signatures.txt')] } diff --git a/client/src/test/java/org/elasticsearch/client/RestClientIntegTests.java b/client/src/test/java/org/elasticsearch/client/RestClientIntegTests.java index 6ee2dc02844..7c4be56040b 100644 --- a/client/src/test/java/org/elasticsearch/client/RestClientIntegTests.java +++ b/client/src/test/java/org/elasticsearch/client/RestClientIntegTests.java @@ -32,7 +32,6 @@ import org.apache.http.entity.StringEntity; import org.apache.http.message.BasicHeader; import org.apache.http.util.EntityUtils; import org.apache.lucene.util.LuceneTestCase; -import org.apache.lucene.util.SuppressForbidden; import org.codehaus.mojo.animal_sniffer.IgnoreJRERequirement; import org.junit.AfterClass; import org.junit.BeforeClass; @@ -40,6 +39,7 @@ import org.junit.BeforeClass; import java.io.IOException; import java.io.InputStreamReader; import java.io.OutputStream; +import java.net.InetAddress; import java.net.InetSocketAddress; import java.util.Arrays; import java.util.Collections; @@ -59,7 +59,6 @@ import static org.hamcrest.CoreMatchers.equalTo; * Works against a real http server, one single host. */ @IgnoreJRERequirement -@SuppressForbidden(reason = "uses sun HttpServer") public class RestClientIntegTests extends LuceneTestCase { private static HttpServer httpServer; @@ -68,7 +67,7 @@ public class RestClientIntegTests extends LuceneTestCase { @BeforeClass public static void startHttpServer() throws Exception { - httpServer = HttpServer.create(new InetSocketAddress(0), 0); + httpServer = HttpServer.create(new InetSocketAddress(InetAddress.getLoopbackAddress(), 0), 0); httpServer.start(); //returns a different status code depending on the path for (int statusCode : getAllStatusCodes()) { @@ -81,7 +80,7 @@ public class RestClientIntegTests extends LuceneTestCase { String headerValue = RandomStrings.randomAsciiOfLengthBetween(random(), 3, 10); defaultHeaders[i] = new BasicHeader(headerName, headerValue); } - restClient = RestClient.builder(new HttpHost(httpServer.getAddress().getHostName(), httpServer.getAddress().getPort())) + restClient = RestClient.builder(new HttpHost(httpServer.getAddress().getHostString(), httpServer.getAddress().getPort())) .setDefaultHeaders(defaultHeaders).build(); } @@ -90,7 +89,6 @@ public class RestClientIntegTests extends LuceneTestCase { } @IgnoreJRERequirement - @SuppressForbidden(reason = "uses sun HttpServer") private static class ResponseHandler implements HttpHandler { private final int statusCode;