diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/FilterC.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/FilterC.java index 3bf14f2d794..42202e5972b 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/FilterC.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/FilterC.java @@ -38,7 +38,7 @@ import javax.servlet.http.HttpSession; @WebFilter(filterName = "CFilter", dispatcherTypes = {DispatcherType.REQUEST}, urlPatterns = {"/*"}, initParams = { @WebInitParam(name = "a", value = "99") -}, asyncSupported = false) + }, asyncSupported = false) @RunAs("admin") public class FilterC implements Filter { diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletC.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletC.java index fe7d9816bf7..52f7328fc7c 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletC.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletC.java @@ -38,7 +38,7 @@ import javax.servlet.http.HttpServletResponse; @DeclareRoles({"alice"}) @WebServlet(urlPatterns = {"/foo/*", "/bah/*"}, name = "CServlet", initParams = { @WebInitParam(name = "x", value = "y") -}, loadOnStartup = 2, asyncSupported = false) + }, loadOnStartup = 2, asyncSupported = false) @MultipartConfig(fileSizeThreshold = 1000, maxFileSize = 2000, maxRequestSize = 3000) @RunAs("admin") @ServletSecurity(value = @HttpConstraint(rolesAllowed = {"fred", "bill", "dorothy"}), httpMethodConstraints = { diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletD.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletD.java index 436a8ca10e9..924c7557021 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletD.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/ServletD.java @@ -24,8 +24,8 @@ import javax.servlet.http.HttpServlet; @WebServlet(urlPatterns = {"/", "/bah/*"}, name = "DServlet", initParams = { @WebInitParam(name = "x", value = "y") -}, loadOnStartup = 1, asyncSupported = false) + }, loadOnStartup = 1, asyncSupported = false) public class ServletD extends HttpServlet { - + // no op } diff --git a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java index 73c73ed4031..b3975b1c4cb 100644 --- a/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java +++ b/jetty-annotations/src/test/java/org/eclipse/jetty/annotations/TestSecurityAnnotationConversions.java @@ -63,16 +63,14 @@ public class TestSecurityAnnotationConversions @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = { "tom", "dick", "harry" - }), httpMethodConstraints = - {@HttpMethodConstraint(value = "GET")}) + }), httpMethodConstraints = {@HttpMethodConstraint(value = "GET")}) public static class Method1Servlet extends HttpServlet { } @ServletSecurity(value = @HttpConstraint(value = EmptyRoleSemantic.PERMIT, transportGuarantee = TransportGuarantee.CONFIDENTIAL, rolesAllowed = { "tom", "dick", "harry" - }), httpMethodConstraints = - {@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)}) + }), httpMethodConstraints = {@HttpMethodConstraint(value = "GET", transportGuarantee = TransportGuarantee.CONFIDENTIAL)}) public static class Method2Servlet extends HttpServlet { } diff --git a/jetty-ant/src/test/java/org/eclipse/jetty/ant/AntBuild.java b/jetty-ant/src/test/java/org/eclipse/jetty/ant/AntBuild.java index a0f20d40c01..d0df7cc29f1 100644 --- a/jetty-ant/src/test/java/org/eclipse/jetty/ant/AntBuild.java +++ b/jetty-ant/src/test/java/org/eclipse/jetty/ant/AntBuild.java @@ -171,7 +171,8 @@ public class AntBuild Matcher mat = pat.getMatcher(line); if (mat.find()) { - int num = 0, count = mat.groupCount(); + int num = 0; + int count = mat.groupCount(); String[] match = new String[count]; while (num++ < count) { diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java index 2a732d2b92f..c6b0dd263dc 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java @@ -657,10 +657,10 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest assertEquals("1523430383", headerInfo.getParameter("nonce")); // test multiple authentications - List headerInfoList = aph.getHeaderInfo("Digest qop=\"auth\", realm=\"thermostat\", nonce=\"1523430383\", " - + "Digest realm=\"thermostat2\", qop=\"auth2\", nonce=\"4522530354\", " - + "Digest qop=\"auth3\", nonce=\"9523570528\", realm=\"thermostat3\", " - + "Digest qop=\"auth4\", nonce=\"3526435321\""); + List headerInfoList = aph.getHeaderInfo("Digest qop=\"auth\", realm=\"thermostat\", nonce=\"1523430383\", " + + "Digest realm=\"thermostat2\", qop=\"auth2\", nonce=\"4522530354\", " + + "Digest qop=\"auth3\", nonce=\"9523570528\", realm=\"thermostat3\", " + + "Digest qop=\"auth4\", nonce=\"3526435321\""); assertTrue(headerInfoList.get(0).getType().equalsIgnoreCase("Digest")); assertEquals("auth", headerInfoList.get(0).getParameter("qop")); @@ -744,8 +744,8 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest assertTrue(headerInfo.getType().equalsIgnoreCase("Negotiate")); assertEquals("TlRMTVNTUAABAAAAB4IIogAAAAAAAAAAAAAAAAAAAAAFAs4OAAAADw==", headerInfo.getBase64()); - headerInfos = aph.getHeaderInfo("Negotiate TlRMTVNTUAABAAAAAAAAAFAs4OAAAADw==, " - + "Negotiate YIIJvwYGKwYBBQUCoIIJszCCCa+gJDAi="); + headerInfos = aph.getHeaderInfo("Negotiate TlRMTVNTUAABAAAAAAAAAFAs4OAAAADw==, " + + "Negotiate YIIJvwYGKwYBBQUCoIIJszCCCa+gJDAi="); assertTrue(headerInfos.get(0).getType().equalsIgnoreCase("Negotiate")); assertEquals("TlRMTVNTUAABAAAAAAAAAFAs4OAAAADw==", headerInfos.get(0).getBase64()); @@ -766,9 +766,9 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest assertEquals("=1523430383=", headerInfo.getParameter("nonce")); // test multiple authentications - List headerInfoList = aph.getHeaderInfo("Digest qop=\"=au=th=\", realm=\"=ther=mostat=\", nonce=\"=152343=0383=\", " - + "Digest realm=\"=thermostat2\", qop=\"=auth2\", nonce=\"=4522530354\", " - + "Digest qop=\"auth3=\", nonce=\"9523570528=\", realm=\"thermostat3=\", "); + List headerInfoList = aph.getHeaderInfo("Digest qop=\"=au=th=\", realm=\"=ther=mostat=\", nonce=\"=152343=0383=\", " + + "Digest realm=\"=thermostat2\", qop=\"=auth2\", nonce=\"=4522530354\", " + + "Digest qop=\"auth3=\", nonce=\"9523570528=\", realm=\"thermostat3=\", "); assertTrue(headerInfoList.get(0).getType().equalsIgnoreCase("Digest")); assertEquals("=au=th=", headerInfoList.get(0).getParameter("qop")); diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java index 70b09e8c3ee..b256901e143 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTLSTest.java @@ -67,6 +67,8 @@ public class HttpClientTLSTest private ServerConnector connector; private HttpClient client; + private SSLSocket sslSocket; + private void startServer(SslContextFactory sslContextFactory, Handler handler) throws Exception { ExecutorThreadPool serverThreads = new ExecutorThreadPool(); @@ -419,7 +421,7 @@ public class HttpClientTLSTest String host = "localhost"; int port = connector.getLocalPort(); Socket socket = new Socket(host, port); - SSLSocket sslSocket = (SSLSocket)clientTLSFactory.getSslContext().getSocketFactory().createSocket(socket, host, port, true); + sslSocket = (SSLSocket)clientTLSFactory.getSslContext().getSocketFactory().createSocket(socket, host, port, true); CountDownLatch handshakeLatch1 = new CountDownLatch(1); AtomicReference session1 = new AtomicReference<>(); sslSocket.addHandshakeCompletedListener(event -> @@ -432,14 +434,12 @@ public class HttpClientTLSTest // In TLS 1.3 the server sends a NewSessionTicket post-handshake message // to enable session resumption and without a read, the message is not processed. - try + + assertThrows(SocketTimeoutException.class, () -> { sslSocket.setSoTimeout(1000); sslSocket.getInputStream().read(); - } - catch (SocketTimeoutException expected) - { - } + }); // The client closes abruptly. socket.close(); diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java index 29658a87fda..a8d9fa48409 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientTest.java @@ -1810,7 +1810,7 @@ public class HttpClientTest extends AbstractHttpClientServerTest } } - public static abstract class RetryListener implements Response.CompleteListener + public abstract static class RetryListener implements Response.CompleteListener { private final HttpClient client; private final String scheme; diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/http/HttpDestinationOverHTTPTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/http/HttpDestinationOverHTTPTest.java index 0c2982d05f4..83d58760876 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/http/HttpDestinationOverHTTPTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/http/HttpDestinationOverHTTPTest.java @@ -45,8 +45,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest { @@ -298,14 +298,7 @@ public class HttpDestinationOverHTTPTest extends AbstractHttpClientServerTest server.stop(); Request request = client.newRequest(host, port).scheme(scenario.getScheme()); - try - { - request.send(); - fail("Request to a closed port must fail"); - } - catch (Exception expected) - { - } + assertThrows(Exception.class, () -> request.send()); long deadline = System.nanoTime() + TimeUnit.SECONDS.toNanos(1); while (!client.getDestinations().isEmpty() && System.nanoTime() < deadline) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java index d890247507b..96a9fdc7bfc 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/ssl/SslBytesServerTest.java @@ -1397,6 +1397,7 @@ public class SslBytesServerTest extends SslBytesTest { case APPLICATION: fail("application data not allows after renegotiate"); + return; // this is just to avoid checkstyle warning case ALERT: break loop; default: diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/util/MultiPartContentProviderTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/util/MultiPartContentProviderTest.java index 0e2505b95c5..e1d855e3e2b 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/util/MultiPartContentProviderTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/util/MultiPartContentProviderTest.java @@ -435,7 +435,7 @@ public class MultiPartContentProviderTest extends AbstractHttpClientServerTest assertTrue(responseLatch.await(5, TimeUnit.SECONDS)); } - private static abstract class AbstractMultiPartHandler extends AbstractHandler + private abstract static class AbstractMultiPartHandler extends AbstractHandler { @Override public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java b/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java index c135a18169a..a9757cfc999 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/MultiPartFormInputStream.java @@ -206,7 +206,7 @@ public class MultiPartFormInputStream public Collection getHeaders(String name) { Collection headers = _headers.getValues(name); - return headers == null ? Collections.emptyList():headers; + return headers == null ? Collections.emptyList() : headers; } @Override diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java index 5ac1df3ac60..f7bf640de51 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpParserTest.java @@ -97,7 +97,7 @@ public class HttpParserTest } @Test - public void testLineParse_Mock_IP() throws Exception + public void testLineParseMockIP() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer("POST /mock/127.0.0.1 HTTP/1.1\r\n" + "\r\n"); @@ -125,7 +125,7 @@ public class HttpParserTest } @Test - public void testLineParse1_RFC2616() throws Exception + public void testLineParse1RFC2616() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer("GET /999\r\n"); @@ -154,7 +154,7 @@ public class HttpParserTest } @Test - public void testLineParse2_RFC2616() throws Exception + public void testLineParse2RFC2616() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer("POST /222 \r\n"); @@ -376,7 +376,7 @@ public class HttpParserTest HttpCompliance.RFC7230, HttpCompliance.RFC2616 }; - String whitespaces[][] = new String[][] + String[][] whitespaces = new String[][] { {" ", "Illegal character SPACE"}, {"\t", "Illegal character HTAB"}, @@ -802,9 +802,9 @@ public class HttpParserTest public void testBadHeaderEncoding() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.0\r\n" - + "H\u00e6der0: value0\r\n" - + "\n\n"); + "GET / HTTP/1.0\r\n" + + "H\u00e6der0: value0\r\n" + + "\n\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -832,7 +832,7 @@ public class HttpParserTest "Foo/Bar: value\r\n", "Foo]Bar: value\r\n", "Foo[Bar: value\r\n", - }; + }; for (int i = 0; i < bad.length; i++) { @@ -1003,16 +1003,16 @@ public class HttpParserTest public void testChunkParse() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" - + "\r\n"); + "GET /chunk HTTP/1.0\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parseAll(parser, buffer); @@ -1033,16 +1033,16 @@ public class HttpParserTest public void testBadChunkParse() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked, identity\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" - + "\r\n"); + "GET /chunk HTTP/1.0\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked, identity\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parseAll(parser, buffer); @@ -1057,17 +1057,17 @@ public class HttpParserTest public void testChunkParseTrailer() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" - + "Trailer: value\r\n" - + "\r\n"); + "GET /chunk HTTP/1.0\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + + "Trailer: value\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parseAll(parser, buffer); @@ -1092,17 +1092,17 @@ public class HttpParserTest public void testChunkParseTrailers() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" - + "Trailer: value\r\n" - + "Foo: bar\r\n" - + "\r\n"); + "GET /chunk HTTP/1.0\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + + "Trailer: value\r\n" + + "Foo: bar\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parseAll(parser, buffer); @@ -1130,16 +1130,16 @@ public class HttpParserTest public void testChunkParseBadTrailer() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" - + "Trailer: value"); + "GET /chunk HTTP/1.0\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + + "Trailer: value"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parseAll(parser, buffer); @@ -1162,15 +1162,15 @@ public class HttpParserTest public void testChunkParseNoTrailer() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n"); + "GET /chunk HTTP/1.0\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parseAll(parser, buffer); @@ -1205,10 +1205,10 @@ public class HttpParserTest public void testEarlyEOF() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /uri HTTP/1.0\r\n" - + "Content-Length: 20\r\n" - + "\r\n" - + "0123456789"); + "GET /uri HTTP/1.0\r\n" + + "Content-Length: 20\r\n" + + "\r\n" + + "0123456789"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parser.atEOF(); @@ -1226,12 +1226,12 @@ public class HttpParserTest public void testChunkEarlyEOF() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /chunk HTTP/1.0\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n"); + "GET /chunk HTTP/1.0\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); parser.atEOF(); @@ -1252,31 +1252,31 @@ public class HttpParserTest public void testMultiParse() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET /mp HTTP/1.0\r\n" - + "Connection: Keep-Alive\r\n" - + "Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" + "GET /mp HTTP/1.0\r\n" + + "Connection: Keep-Alive\r\n" + + "Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + - + "\r\n" + "\r\n" + - + "POST /foo HTTP/1.0\r\n" - + "Connection: Keep-Alive\r\n" - + "Header2: value2\r\n" - + "Content-Length: 0\r\n" - + "\r\n" + "POST /foo HTTP/1.0\r\n" + + "Connection: Keep-Alive\r\n" + + "Header2: value2\r\n" + + "Content-Length: 0\r\n" + + "\r\n" + - + "PUT /doodle HTTP/1.0\r\n" - + "Connection: close\r\n" - + "Header3: value3\r\n" - + "Content-Length: 10\r\n" - + "\r\n" - + "0123456789\r\n"); + "PUT /doodle HTTP/1.0\r\n" + + "Connection: close\r\n" + + "Header3: value3\r\n" + + "Content-Length: 10\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1317,32 +1317,31 @@ public class HttpParserTest public void testMultiParseEarlyEOF() throws Exception { ByteBuffer buffer0 = BufferUtil.toBuffer( - "GET /mp HTTP/1.0\r\n" - + "Connection: Keep-Alive\r\n"); + "GET /mp HTTP/1.0\r\n" + + "Connection: Keep-Alive\r\n"); - ByteBuffer buffer1 = BufferUtil.toBuffer("Header1: value1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "a;\r\n" - + "0123456789\r\n" - + "1a\r\n" - + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" - + "0\r\n" + ByteBuffer buffer1 = BufferUtil.toBuffer("Header1: value1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "a;\r\n" + + "0123456789\r\n" + + "1a\r\n" + + "ABCDEFGHIJKLMNOPQRSTUVWXYZ\r\n" + + "0\r\n" + - + "\r\n" + "\r\n" + - + "POST /foo HTTP/1.0\r\n" - + "Connection: Keep-Alive\r\n" - + "Header2: value2\r\n" - + "Content-Length: 0\r\n" - + "\r\n" + "POST /foo HTTP/1.0\r\n" + + "Connection: Keep-Alive\r\n" + + "Header2: value2\r\n" + + "Content-Length: 0\r\n" + + "\r\n" + - + "PUT /doodle HTTP/1.0\r\n" - + "Connection: close\r\n" - + "Header3: value3\r\n" - + "Content-Length: 10\r\n" - + "\r\n" - + "0123456789\r\n"); + "PUT /doodle HTTP/1.0\r\n" + + "Connection: close\r\n" + "Header3: value3\r\n" + + "Content-Length: 10\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1384,11 +1383,11 @@ public class HttpParserTest public void testResponseParse0() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 200 Correct\r\n" - + "Content-Length: 10\r\n" - + "Content-Type: text/plain\r\n" - + "\r\n" - + "0123456789\r\n"); + "HTTP/1.1 200 Correct\r\n" + + "Content-Length: 10\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1405,9 +1404,9 @@ public class HttpParserTest public void testResponseParse1() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 304 Not-Modified\r\n" - + "Connection: close\r\n" - + "\r\n"); + "HTTP/1.1 304 Not-Modified\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1423,15 +1422,15 @@ public class HttpParserTest public void testResponseParse2() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 204 No-Content\r\n" - + "Header: value\r\n" - + "\r\n" + "HTTP/1.1 204 No-Content\r\n" + + "Header: value\r\n" + + "\r\n" + - + "HTTP/1.1 200 Correct\r\n" - + "Content-Length: 10\r\n" - + "Content-Type: text/plain\r\n" - + "\r\n" - + "0123456789\r\n"); + "HTTP/1.1 200 Correct\r\n" + + "Content-Length: 10\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1459,11 +1458,11 @@ public class HttpParserTest public void testResponseParse3() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 200\r\n" - + "Content-Length: 10\r\n" - + "Content-Type: text/plain\r\n" - + "\r\n" - + "0123456789\r\n"); + "HTTP/1.1 200\r\n" + + "Content-Length: 10\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1480,11 +1479,11 @@ public class HttpParserTest public void testResponseParse4() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 200 \r\n" - + "Content-Length: 10\r\n" - + "Content-Type: text/plain\r\n" - + "\r\n" - + "0123456789\r\n"); + "HTTP/1.1 200 \r\n" + + "Content-Length: 10\r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1501,10 +1500,10 @@ public class HttpParserTest public void testResponseEOFContent() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 200 \r\n" - + "Content-Type: text/plain\r\n" - + "\r\n" - + "0123456789\r\n"); + "HTTP/1.1 200 \r\n" + + "Content-Type: text/plain\r\n" + + "\r\n" + + "0123456789\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1524,9 +1523,9 @@ public class HttpParserTest public void testResponse304WithContentLength() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 304 found\r\n" - + "Content-Length: 10\r\n" - + "\r\n"); + "HTTP/1.1 304 found\r\n" + + "Content-Length: 10\r\n" + + "\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1543,9 +1542,9 @@ public class HttpParserTest public void testResponse101WithTransferEncoding() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 101 switching protocols\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n"); + "HTTP/1.1 101 switching protocols\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1562,9 +1561,9 @@ public class HttpParserTest public void testResponseReasonIso8859_1() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 302 déplacé temporairement\r\n" - + "Content-Length: 0\r\n" - + "\r\n", StandardCharsets.ISO_8859_1); + "HTTP/1.1 302 déplacé temporairement\r\n" + + "Content-Length: 0\r\n" + + "\r\n", StandardCharsets.ISO_8859_1); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1578,12 +1577,12 @@ public class HttpParserTest public void testSeekEOF() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 200 OK\r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n" - + "\r\n" // extra CRLF ignored - + "HTTP/1.1 400 OK\r\n"); // extra data causes close ?? + "HTTP/1.1 200 OK\r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n" + + "\r\n" + // extra CRLF ignored + "HTTP/1.1 400 OK\r\n"); // extra data causes close ?? HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1610,10 +1609,10 @@ public class HttpParserTest public void testNoURI() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET\r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET\r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1632,10 +1631,10 @@ public class HttpParserTest public void testNoURI2() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET \r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET \r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1654,10 +1653,10 @@ public class HttpParserTest public void testUnknownReponseVersion() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HPPT/7.7 200 OK\r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "HPPT/7.7 200 OK\r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1676,10 +1675,10 @@ public class HttpParserTest public void testNoStatus() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1\r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "HTTP/1.1\r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1698,10 +1697,10 @@ public class HttpParserTest public void testNoStatus2() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "HTTP/1.1 \r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "HTTP/1.1 \r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.ResponseHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1720,10 +1719,10 @@ public class HttpParserTest public void testBadRequestVersion() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HPPT/7.7\r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HPPT/7.7\r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1738,10 +1737,10 @@ public class HttpParserTest assertEquals(HttpParser.State.CLOSED, parser.getState()); buffer = BufferUtil.toBuffer( - "GET / HTTP/1.01\r\n" - + "Content-Length: 0\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.01\r\n" + + "Content-Length: 0\r\n" + + "Connection: close\r\n" + + "\r\n"); handler = new Handler(); parser = new HttpParser(handler); @@ -1760,10 +1759,10 @@ public class HttpParserTest public void testBadCR() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.0\r\n" - + "Content-Length: 0\r" - + "Connection: close\r" - + "\r"); + "GET / HTTP/1.0\r\n" + + "Content-Length: 0\r" + + "Connection: close\r" + + "\r"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1777,10 +1776,10 @@ public class HttpParserTest assertEquals(HttpParser.State.CLOSED, parser.getState()); buffer = BufferUtil.toBuffer( - "GET / HTTP/1.0\r" - + "Content-Length: 0\r" - + "Connection: close\r" - + "\r"); + "GET / HTTP/1.0\r" + + "Content-Length: 0\r" + + "Connection: close\r" + + "\r"); handler = new Handler(); parser = new HttpParser(handler); @@ -1798,10 +1797,10 @@ public class HttpParserTest public void testBadContentLength0() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.0\r\n" - + "Content-Length: abc\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.0\r\n" + + "Content-Length: abc\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1820,10 +1819,10 @@ public class HttpParserTest public void testBadContentLength1() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.0\r\n" - + "Content-Length: 9999999999999999999999999999999999999999999999\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.0\r\n" + + "Content-Length: 9999999999999999999999999999999999999999999999\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1842,10 +1841,10 @@ public class HttpParserTest public void testBadContentLength2() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.0\r\n" - + "Content-Length: 1.5\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.0\r\n" + + "Content-Length: 1.5\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1864,12 +1863,12 @@ public class HttpParserTest public void testMultipleContentLengthWithLargerThenCorrectValue() { ByteBuffer buffer = BufferUtil.toBuffer( - "POST / HTTP/1.1\r\n" - + "Content-Length: 2\r\n" - + "Content-Length: 1\r\n" - + "Connection: close\r\n" - + "\r\n" - + "X"); + "POST / HTTP/1.1\r\n" + + "Content-Length: 2\r\n" + + "Content-Length: 1\r\n" + + "Connection: close\r\n" + + "\r\n" + + "X"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1888,12 +1887,12 @@ public class HttpParserTest public void testMultipleContentLengthWithCorrectThenLargerValue() { ByteBuffer buffer = BufferUtil.toBuffer( - "POST / HTTP/1.1\r\n" - + "Content-Length: 1\r\n" - + "Content-Length: 2\r\n" - + "Connection: close\r\n" - + "\r\n" - + "X"); + "POST / HTTP/1.1\r\n" + + "Content-Length: 1\r\n" + + "Content-Length: 2\r\n" + + "Connection: close\r\n" + + "\r\n" + + "X"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1912,15 +1911,15 @@ public class HttpParserTest public void testTransferEncodingChunkedThenContentLength() { ByteBuffer buffer = BufferUtil.toBuffer( - "POST /chunk HTTP/1.1\r\n" - + "Host: localhost\r\n" - + "Transfer-Encoding: chunked\r\n" - + "Content-Length: 1\r\n" - + "\r\n" - + "1\r\n" - + "X\r\n" - + "0\r\n" - + "\r\n"); + "POST /chunk HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "Transfer-Encoding: chunked\r\n" + + "Content-Length: 1\r\n" + + "\r\n" + + "1\r\n" + + "X\r\n" + + "0\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler, HttpCompliance.RFC2616_LEGACY); @@ -1941,15 +1940,16 @@ public class HttpParserTest public void testContentLengthThenTransferEncodingChunked() { ByteBuffer buffer = BufferUtil.toBuffer( - "POST /chunk HTTP/1.1\r\n" - + "Host: localhost\r\n" - + "Content-Length: 1\r\n" - + "Transfer-Encoding: chunked\r\n" - + "\r\n" - + "1\r\n" - + "X\r\n" - + "0\r\n" - + "\r\n"); + "POST /chunk HTTP/1.1\r\n" + + "Host: localhost\r\n" + + "Content-Length: 1\r\n" + + "Transfer-Encoding: chunked\r\n" + + "\r\n" + + "1\r\n" + + "X\r\n" + + "0\r\n" + + "\r\n"); + HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler, HttpCompliance.RFC2616_LEGACY); @@ -1970,10 +1970,10 @@ public class HttpParserTest public void testHost() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: host\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: host\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -1986,9 +1986,9 @@ public class HttpParserTest public void testUriHost11() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET http://host/ HTTP/1.1\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET http://host/ HTTP/1.1\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2002,8 +2002,8 @@ public class HttpParserTest public void testUriHost10() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET http://host/ HTTP/1.0\r\n" - + "\r\n"); + "GET http://host/ HTTP/1.0\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2017,9 +2017,9 @@ public class HttpParserTest public void testNoHost() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2031,10 +2031,10 @@ public class HttpParserTest public void testIPHost() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: 192.168.0.1\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: 192.168.0.1\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2048,10 +2048,10 @@ public class HttpParserTest { Assumptions.assumeTrue(Net.isIpv6InterfaceAvailable()); ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: [::1]\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: [::1]\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2066,10 +2066,10 @@ public class HttpParserTest try (StacklessLogging s = new StacklessLogging(HttpParser.class)) { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: [::1\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: [::1\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2082,10 +2082,10 @@ public class HttpParserTest public void testHostPort() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: myhost:8888\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: myhost:8888\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2098,10 +2098,10 @@ public class HttpParserTest public void testHostBadPort() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: myhost:testBadPort\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: myhost:testBadPort\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2113,10 +2113,10 @@ public class HttpParserTest public void testIPHostPort() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: 192.168.0.1:8888\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: 192.168.0.1:8888\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2130,10 +2130,10 @@ public class HttpParserTest { Assumptions.assumeTrue(Net.isIpv6InterfaceAvailable()); ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host: [::1]:8888\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host: [::1]:8888\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); @@ -2146,10 +2146,10 @@ public class HttpParserTest public void testEmptyHostPort() throws Exception { ByteBuffer buffer = BufferUtil.toBuffer( - "GET / HTTP/1.1\r\n" - + "Host:\r\n" - + "Connection: close\r\n" - + "\r\n"); + "GET / HTTP/1.1\r\n" + + "Host:\r\n" + + "Connection: close\r\n" + + "\r\n"); HttpParser.RequestHandler handler = new Handler(); HttpParser parser = new HttpParser(handler); diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java index f2239e564e6..27d494e3649 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/HttpTester.java @@ -493,7 +493,7 @@ public class HttpTester } } - abstract public MetaData getInfo(); + public abstract MetaData getInfo(); @Override public int getHeaderCacheSize() diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java index 9a940f6c50d..a8c1d986119 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartFormInputStreamTest.java @@ -77,9 +77,9 @@ public class MultiPartFormInputStreamTest "Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n" + "Content-Type: application/octet-stream\r\n\r\n" + "How now brown cow." + - "\r\n--" + boundary + "-\r\n" - + "Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n" - + "\r\n"; + "\r\n--" + boundary + "-\r\n" + + "Content-Disposition: form-data; name=\"fileup\"; filename=\"test.upload\"\r\n" + + "\r\n"; MultipartConfigElement config = new MultipartConfigElement(_dirname, 1024, 3072, 50); MultiPartFormInputStream mpis = new MultiPartFormInputStream(new ByteArrayInputStream(str.getBytes()), diff --git a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java index a9502116c1d..09e61f59572 100644 --- a/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java +++ b/jetty-http/src/test/java/org/eclipse/jetty/http/MultiPartParserTest.java @@ -173,13 +173,13 @@ public class MultiPartParserTest }; MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name0: value0\r\n" - + "name1 :value1 \r\n" - + "name2:value\r\n" - + " 2\r\n" - + "\r\n" - + "Content"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name0: value0\r\n" + + "name1 :value1 \r\n" + + "name2:value\r\n" + + " 2\r\n" + + "\r\n" + + "Content"); parser.parse(data, false); assertThat(parser.getState(), is(State.FIRST_OCTETS)); @@ -193,11 +193,11 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name: value\r\n" - + "\r\n" - + "\r\n" - + "--BOUNDARY"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name: value\r\n" + + "\r\n" + + "\r\n" + + "--BOUNDARY"); parser.parse(data, false); assertThat(parser.getState(), is(State.DELIMITER)); assertThat(data.remaining(), is(0)); @@ -211,10 +211,10 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name: value\r\n" - + "\r\n" - + "--BOUNDARY"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name: value\r\n" + + "\r\n" + + "--BOUNDARY"); parser.parse(data, false); assertThat(parser.getState(), is(State.DELIMITER)); assertThat(data.remaining(), is(0)); @@ -228,10 +228,10 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name: value\r\n" - + "\r\n" - + "-"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name: value\r\n" + + "\r\n" + + "-"); parser.parse(data, false); data = BufferUtil.toBuffer("Content!"); parser.parse(data, false); @@ -248,10 +248,10 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name: value\n" - + "\r\n" - + "Hello\r\n"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name: value\n" + + "\r\n" + + "Hello\r\n"); parser.parse(data, false); assertThat(parser.getState(), is(State.OCTETS)); assertThat(data.remaining(), is(0)); @@ -259,18 +259,18 @@ public class MultiPartParserTest assertThat(handler.content, Matchers.contains("Hello")); data = BufferUtil.toBuffer( - "Now is the time for all good ment to come to the aid of the party.\r\n" - + "How now brown cow.\r\n" - + "The quick brown fox jumped over the lazy dog.\r\n" - + "this is not a --BOUNDARY\r\n"); + "Now is the time for all good ment to come to the aid of the party.\r\n" + + "How now brown cow.\r\n" + + "The quick brown fox jumped over the lazy dog.\r\n" + + "this is not a --BOUNDARY\r\n"); parser.parse(data, false); assertThat(parser.getState(), is(State.OCTETS)); assertThat(data.remaining(), is(0)); assertThat(handler.fields, Matchers.contains("name: value", "<>")); - assertThat(handler.content, Matchers.contains("Hello", "\r\n", "Now is the time for all good ment to come to the aid of the party.\r\n" - + "How now brown cow.\r\n" - + "The quick brown fox jumped over the lazy dog.\r\n" - + "this is not a --BOUNDARY")); + assertThat(handler.content, Matchers.contains("Hello", "\r\n", "Now is the time for all good ment to come to the aid of the party.\r\n" + + "How now brown cow.\r\n" + + "The quick brown fox jumped over the lazy dog.\r\n" + + "this is not a --BOUNDARY")); } @Test @@ -279,11 +279,11 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name: value\n" - + "\r\n" - + "Hello\r\n" - + "--BOUNDARY"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name: value\n" + + "\r\n" + + "Hello\r\n" + + "--BOUNDARY"); parser.parse(data, false); assertThat(parser.getState(), is(State.DELIMITER)); assertThat(data.remaining(), is(0)); @@ -297,21 +297,21 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" - + "name: value\n" - + "\r\n" - + "Now is the time for all good ment to come to the aid of the party.\r\n" - + "How now brown cow.\r\n" - + "The quick brown fox jumped over the lazy dog.\r\n" - + "\r\n" - + "--BOUNDARY"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\r\n" + + "name: value\n" + + "\r\n" + + "Now is the time for all good ment to come to the aid of the party.\r\n" + + "How now brown cow.\r\n" + + "The quick brown fox jumped over the lazy dog.\r\n" + + "\r\n" + + "--BOUNDARY"); parser.parse(data, false); assertThat(parser.getState(), is(State.DELIMITER)); assertThat(data.remaining(), is(0)); assertThat(handler.fields, Matchers.contains("name: value", "<>")); - assertThat(handler.content, Matchers.contains("Now is the time for all good ment to come to the aid of the party.\r\n" - + "How now brown cow.\r\n" - + "The quick brown fox jumped over the lazy dog.\r\n", "<>")); + assertThat(handler.content, Matchers.contains("Now is the time for all good ment to come to the aid of the party.\r\n" + + "How now brown cow.\r\n" + + "The quick brown fox jumped over the lazy dog.\r\n", "<>")); } @Test @@ -321,21 +321,21 @@ public class MultiPartParserTest MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); //boundary still requires carriage return - ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\n" - + "name: value\n" - + "\n" - + "Now is the time for all good men to come to the aid of the party.\n" - + "How now brown cow.\n" - + "The quick brown fox jumped over the lazy dog.\n" - + "\r\n" - + "--BOUNDARY"); + ByteBuffer data = BufferUtil.toBuffer("--BOUNDARY\n" + + "name: value\n" + + "\n" + + "Now is the time for all good men to come to the aid of the party.\n" + + "How now brown cow.\n" + + "The quick brown fox jumped over the lazy dog.\n" + + "\r\n" + + "--BOUNDARY"); parser.parse(data, false); assertThat(parser.getState(), is(State.DELIMITER)); assertThat(data.remaining(), is(0)); assertThat(handler.fields, Matchers.contains("name: value", "<>")); - assertThat(handler.content, Matchers.contains("Now is the time for all good men to come to the aid of the party.\n" - + "How now brown cow.\n" - + "The quick brown fox jumped over the lazy dog.\n", "<>")); + assertThat(handler.content, Matchers.contains("Now is the time for all good men to come to the aid of the party.\n" + + "How now brown cow.\n" + + "The quick brown fox jumped over the lazy dog.\n", "<>")); } @Test @@ -377,17 +377,17 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("" - + "--BOUNDARY\r\n" - + "name: value\n" - + "\r\n" - + "Hello\r\n" - + "--BOUNDARY--" - + "epilogue here:" - + "\r\n" - + "--BOUNDARY--" - + "\r\n" - + "--BOUNDARY"); + ByteBuffer data = BufferUtil.toBuffer("" + + "--BOUNDARY\r\n" + + "name: value\n" + + "\r\n" + + "Hello\r\n" + + "--BOUNDARY--" + + "epilogue here:" + + "\r\n" + + "--BOUNDARY--" + + "\r\n" + + "--BOUNDARY"); parser.parse(data, false); assertThat(parser.getState(), is(State.DELIMITER)); @@ -404,20 +404,20 @@ public class MultiPartParserTest TestHandler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "BOUNDARY"); - ByteBuffer data = BufferUtil.toBuffer("" - + "--BOUNDARY\r\n" - + "name: value\n" - + "\r\n" - + "Hello" - + "\r\n" - + "--BOUNDARY\r\n" - + "powerLevel: 9001\n" - + "\r\n" - + "secondary" - + "\r\n" - + "content" - + "\r\n--BOUNDARY--" - + "epilogue here"); + ByteBuffer data = BufferUtil.toBuffer("" + + "--BOUNDARY\r\n" + + "name: value\n" + + "\r\n" + + "Hello" + + "\r\n" + + "--BOUNDARY\r\n" + + "powerLevel: 9001\n" + + "\r\n" + + "secondary" + + "\r\n" + + "content" + + "\r\n--BOUNDARY--" + + "epilogue here"); /* Test First Content Section */ parser.parse(data, false); @@ -612,21 +612,21 @@ public class MultiPartParserTest dataSeg.limit(length); assertThat("Third " + i, parser.parse(dataSeg, true), is(true)); - assertThat(handler.fields, Matchers.contains("Content-Disposition: form-data; name=\"text\"", "<>" - , "Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"" - , "Content-Type: text/plain", "<>" - , "Content-Disposition: form-data; name=\"file2\"; filename=\"a.html\"" - , "Content-Type: text/html", "<>" - , "Field1: value1", "Field2: value2", "Field3: value3" - , "Field4: value4", "Field5: value5", "Field6: value6" - , "Field7: value7", "Field8: value8", "Field9: value 9", "<>" - , "Field1: value1", "<>")); + assertThat(handler.fields, Matchers.contains("Content-Disposition: form-data; name=\"text\"", "<>", + "Content-Disposition: form-data; name=\"file1\"; filename=\"a.txt\"", + "Content-Type: text/plain", "<>", + "Content-Disposition: form-data; name=\"file2\"; filename=\"a.html\"", + "Content-Type: text/html", "<>", + "Field1: value1", "Field2: value2", "Field3: value3", + "Field4: value4", "Field5: value5", "Field6: value6", + "Field7: value7", "Field8: value8", "Field9: value 9", "<>", + "Field1: value1", "<>")); - assertThat(handler.contentString(), is("text default" + "<>" - + "Content of a.txt.\n" + "<>" - + "Content of a.html.\n" + "<>" - + "<>" - + "But the amount of denudation which the strata have\n" + + assertThat(handler.contentString(), is("text default" + "<>" + + "Content of a.txt.\n" + "<>" + + "Content of a.html.\n" + "<>" + + "<>" + + "But the amount of denudation which the strata have\n" + "in many places suffered, independently of the rate\n" + "of accumulation of the degraded matter, probably\n" + "offers the best evidence of the lapse of time. I remember\n" + @@ -670,18 +670,18 @@ public class MultiPartParserTest }; MultiPartParser parser = new MultiPartParser(handler, "WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW"); - ByteBuffer data = BufferUtil.toBuffer("" - + "Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" + - "\r\n" + - "--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" + - "Content-Disposition: form-data; name=\"part1\"\r\n" + - "\n" + - "wNfミxVam﾿t\r\n" + - "--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\n" + - "Content-Disposition: form-data; name=\"part2\"\r\n" + - "\r\n" + - "&ᄈᄎ￙ᅱᅢO\r\n" + - "--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW--"); + ByteBuffer data = BufferUtil.toBuffer("" + + "Content-Type: multipart/form-data; boundary=WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" + + "\r\n" + + "--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\r\n" + + "Content-Disposition: form-data; name=\"part1\"\r\n" + + "\n" + + "wNfミxVam﾿t\r\n" + + "--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW\n" + + "Content-Disposition: form-data; name=\"part2\"\r\n" + + "\r\n" + + "&ᄈᄎ￙ᅱᅢO\r\n" + + "--WebKitFormBoundary7MA4YWf7OaKlSxkTrZu0gW--"); parser.parse(data, true); assertThat(parser.getState(), is(State.END)); diff --git a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java index f86e132fb2e..8bc64030bbf 100644 --- a/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java +++ b/jetty-http2/http2-client/src/test/java/org/eclipse/jetty/http2/client/StreamResetTest.java @@ -881,7 +881,7 @@ public class StreamResetTest extends AbstractTest // Try to write again, must fail immediately. output.write(0xFF); } - catch (IOException xx) + catch (IOException e) { writeLatch2.countDown(); } diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java index ed4ac09d86a..a24de7a396a 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackContextTest.java @@ -104,7 +104,7 @@ public class HpackContextTest new HttpField("name", "v3"), new HttpField("name", "v4"), new HttpField("name", "v5"), - }; + }; Entry[] entry = new Entry[field.length]; @@ -197,7 +197,7 @@ public class HpackContextTest new HttpField("fo8", "b8r"), new HttpField("fo9", "b9r"), new HttpField("foA", "bAr"), - }; + }; Entry[] entry = new Entry[100]; @@ -324,7 +324,7 @@ public class HpackContextTest new HttpField("fo8", "b8r"), new HttpField("fo9", "b9r"), new HttpField("foA", "bAr"), - }; + }; Entry[] entry = new Entry[field.length]; // Add 5 entries diff --git a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java index d9a59639950..2fada9a66c5 100644 --- a/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java +++ b/jetty-http2/http2-hpack/src/test/java/org/eclipse/jetty/http2/hpack/HpackEncoderTest.java @@ -56,7 +56,7 @@ public class HpackEncoderTest new HttpField("fo8", "b8r"), new HttpField("fo9", "b9r"), new HttpField("foA", "bAr"), - }; + }; // Add 4 entries for (int i = 0; i <= 3; i++) diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslHandshakeListener.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslHandshakeListener.java index 3c118bbadde..6706e269ba3 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslHandshakeListener.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ssl/SslHandshakeListener.java @@ -35,6 +35,7 @@ public interface SslHandshakeListener extends EventListener *

Callback method invoked when the TLS handshake succeeds.

* * @param event the event object carrying information about the TLS handshake event + * @throws SSLException if any error happen during handshake */ default void handshakeSucceeded(Event event) throws SSLException { diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java index a9b198eaced..0463922154f 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/IOTest.java @@ -43,6 +43,7 @@ import java.util.concurrent.TimeUnit; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.IO; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.condition.OS; @@ -93,14 +94,8 @@ public class IOTest assertEquals(-1, server.getInputStream().read()); // but cannot write - try - { - client.getOutputStream().write(1); - fail("exception expected"); - } - catch (SocketException expected) - { - } + Assertions.assertThrows(SocketException.class, () -> client.getOutputStream().write(1)); + // but can still write in opposite direction. server.getOutputStream().write(1); @@ -110,14 +105,7 @@ public class IOTest server.shutdownInput(); // now we EOF instead of reading -1 - try - { - server.getInputStream().read(); - fail("exception expected"); - } - catch (SocketException expected) - { - } + Assertions.assertThrows(SocketException.class, () -> server.getInputStream().read()); // but can still write in opposite direction. server.getOutputStream().write(1); @@ -127,14 +115,7 @@ public class IOTest client.shutdownInput(); // now we EOF instead of reading -1 - try - { - client.getInputStream().read(); - fail("exception expected"); - } - catch (SocketException expected) - { - } + Assertions.assertThrows(SocketException.class, () -> client.getInputStream().read()); // But we can still write at the server (data which will never be read) server.getOutputStream().write(1); @@ -146,14 +127,7 @@ public class IOTest server.shutdownOutput(); // and now we can't write - try - { - server.getOutputStream().write(1); - fail("exception expected"); - } - catch (SocketException expected) - { - } + Assertions.assertThrows(SocketException.class, () -> server.getOutputStream().write(1)); // but the sockets are still open assertFalse(client.isClosed()); diff --git a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java index 31397d3288c..994b2a39f41 100644 --- a/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java +++ b/jetty-io/src/test/java/org/eclipse/jetty/io/SslConnectionTest.java @@ -461,6 +461,7 @@ public class SslConnectionTest } catch (SocketTimeoutException e) { + // no op } assertTrue(__onIncompleteFlush.get()); @@ -507,6 +508,7 @@ public class SslConnectionTest } catch (SocketTimeoutException e) { + // no op } __blockFor.set(0); diff --git a/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java b/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java index 7f9cd1cafc5..e62320ea54a 100644 --- a/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java +++ b/jetty-jaas/src/test/java/org/eclipse/jetty/jaas/spi/PropertyFileLoginModuleTest.java @@ -18,12 +18,6 @@ package org.eclipse.jetty.jaas.spi; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.hamcrest.Matchers.not; -import static org.junit.jupiter.api.Assertions.assertEquals; - import java.io.File; import java.util.HashMap; @@ -33,6 +27,12 @@ import org.eclipse.jetty.jaas.callback.DefaultCallbackHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.not; +import static org.junit.jupiter.api.Assertions.assertEquals; + public class PropertyFileLoginModuleTest { @Test diff --git a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java b/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java index 0b18009b0c0..af44682b588 100644 --- a/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java +++ b/jetty-jndi/src/test/java/org/eclipse/jetty/jndi/java/TestJNDI.java @@ -472,9 +472,9 @@ public class TestJNDI ((Context)zzz.lookup("java:comp")).bind("crud2", "xxx2"); fail("Should not be able to write to locked context"); } - catch (NamingException ne) + catch (NamingException e) { - assertThat(ne.getMessage(), Matchers.containsString("immutable")); + assertThat(e.getMessage(), Matchers.containsString("immutable")); } finally { @@ -492,9 +492,9 @@ public class TestJNDI ((Context)zzz.lookup("java:comp")).bind("foo", "bar"); fail("Should not be able to write to locked context"); } - catch (NamingException ne) + catch (NamingException e) { - assertThat(ne.getMessage(), Matchers.containsString("immutable")); + assertThat(e.getMessage(), Matchers.containsString("immutable")); } finally { diff --git a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java index 2a09f98bc73..1e3f34f8f80 100644 --- a/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java +++ b/jetty-maven-plugin/src/test/java/org/eclipse/jetty/maven/plugin/it/TestGetContent.java @@ -73,8 +73,8 @@ public class TestGetContent url += pathToCheck; } String response = httpClient.GET(url).getContentAsString(); - assertTrue(response.contains(contentCheck), "it test " + System.getProperty("maven.it.name") - + ", response not contentCheck: " + contentCheck + ", response:" + response); + assertTrue(response.contains(contentCheck), "it test " + System.getProperty("maven.it.name") + + ", response not contentCheck: " + contentCheck + ", response:" + response); System.out.println("contentCheck"); } if (Boolean.getBoolean("helloTestServlet")) diff --git a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java index 641d79d805c..ec676244cea 100644 --- a/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java +++ b/jetty-osgi/test-jetty-osgi/src/test/java/org/eclipse/jetty/osgi/test/TestOSGiUtil.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -113,15 +114,15 @@ public class TestOSGiUtil String mavenRepoPath = System.getProperty("mavenRepoPath"); if (!StringUtil.isBlank(mavenRepoPath)) { - res.add( systemProperty( "org.ops4j.pax.url.mvn.localRepository" ).value( mavenRepoPath ) ); - res.add( systemProperty( "org.ops4j.pax.url.mvn.defaultRepositories" ).value( "file://" + mavenRepoPath + "@id=local.repo") ); - res.add( systemProperty( "org.ops4j.pax.url.mvn.useFallbackRepositories").value( Boolean.FALSE.toString() ) ); - res.add( systemProperty( "org.ops4j.pax.url.mvn.repositories").value( "+https://repo1.maven.org/maven2@id=maven.central.repo" ) ); + res.add(systemProperty("org.ops4j.pax.url.mvn.localRepository").value(mavenRepoPath)); + res.add(systemProperty("org.ops4j.pax.url.mvn.defaultRepositories").value("file://" + mavenRepoPath + "@id=local.repo")); + res.add(systemProperty("org.ops4j.pax.url.mvn.useFallbackRepositories").value(Boolean.FALSE.toString())); + res.add(systemProperty("org.ops4j.pax.url.mvn.repositories").value("+https://repo1.maven.org/maven2@id=maven.central.repo")); } String settingsFilePath = System.getProperty("settingsFilePath"); if (!StringUtil.isBlank(settingsFilePath)) { - res.add( systemProperty( "org.ops4j.pax.url.mvn.settings" ).value( System.getProperty( "settingsFilePath" ) ) ); + res.add(systemProperty("org.ops4j.pax.url.mvn.settings").value(System.getProperty("settingsFilePath"))); } res.add(mavenBundle().groupId("org.ow2.asm").artifactId("asm").versionAsInProject().start()); res.add(mavenBundle().groupId("org.ow2.asm").artifactId("asm-commons").versionAsInProject().start()); @@ -194,11 +195,11 @@ public class TestOSGiUtil for (Bundle b : bundleContext.getBundles()) { Bundle prevBundle = _bundles.put(b.getSymbolicName(), b); - String err = prevBundle != null ? "2 versions of the bundle " + b.getSymbolicName() - + " " - + b.getHeaders().get("Bundle-Version") - + " and " - + prevBundle.getHeaders().get("Bundle-Version") : ""; + String err = prevBundle != null ? "2 versions of the bundle " + b.getSymbolicName() + + " " + + b.getHeaders().get("Bundle-Version") + + " and " + + prevBundle.getHeaders().get("Bundle-Version") : ""; assertNull(err, prevBundle); } return _bundles.get(symbolicName); @@ -229,16 +230,16 @@ public class TestOSGiUtil { diagnoseNonActiveOrNonResolvedBundle(b); } - assertTrue("Bundle: " + b - + " (state should be " - + "ACTIVE[" - + Bundle.ACTIVE - + "] or RESOLVED[" - + Bundle.RESOLVED - + "]" - + ", but was [" - + b.getState() - + "])", (b.getState() == Bundle.ACTIVE) || (b.getState() == Bundle.RESOLVED)); + assertTrue("Bundle: " + b + + " (state should be " + + "ACTIVE[" + + Bundle.ACTIVE + + "] or RESOLVED[" + + Bundle.RESOLVED + + "]" + + ", but was [" + + b.getState() + + "])", (b.getState() == Bundle.ACTIVE) || (b.getState() == Bundle.RESOLVED)); } } diff --git a/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java b/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java index a9369c4357f..1d43f750170 100644 --- a/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java +++ b/jetty-plus/src/test/java/org/eclipse/jetty/plus/annotation/LifeCycleCallbackCollectionTest.java @@ -18,20 +18,15 @@ package org.eclipse.jetty.plus.annotation; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.anEmptyMap; -import static org.hamcrest.Matchers.hasEntry; -import static org.hamcrest.Matchers.hasKey; -import static org.hamcrest.Matchers.hasSize; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.fail; - import java.lang.reflect.Method; import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.hasSize; +import static org.junit.jupiter.api.Assertions.fail; + public class LifeCycleCallbackCollectionTest { diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java index 842aea1b2d8..c64d64fb571 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java @@ -1533,7 +1533,7 @@ public class AsyncMiddleManServletTest return out.toByteArray(); } - private static abstract class HrefTransformer implements AsyncMiddleManServlet.ContentTransformer + private abstract static class HrefTransformer implements AsyncMiddleManServlet.ContentTransformer { private static final String PREFIX = "http://localhost/q="; private final HrefParser parser = new HrefParser(); diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ReverseProxyTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ReverseProxyTest.java index 5a032128670..fc596ba7a99 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ReverseProxyTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/ReverseProxyTest.java @@ -141,9 +141,11 @@ public class ReverseProxyTest } }); startProxy(new HashMap() - {{ - put("preserveHost", "true"); - }}); + { + { + put("preserveHost", "true"); + } + }); startClient(); ContentResponse response = client.newRequest("localhost", proxyConnector.getLocalPort()).send(); diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderPatternRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderPatternRuleTest.java index 49136242fde..53d969875e1 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderPatternRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderPatternRuleTest.java @@ -42,7 +42,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase public void testHeaderWithTextValues() throws IOException { // different keys - String headers[][] = { + String[][] headers = { {"hnum#1", "test1"}, {"hnum#2", "2test2"}, {"hnum#3", "test3"} @@ -53,7 +53,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase @Test public void testHeaderWithNumberValues() throws IOException { - String headers[][] = { + String[][] headers = { {"hello", "1"}, {"hello", "-1"}, {"hello", "100"}, @@ -70,7 +70,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase @Test public void testHeaderOverwriteValues() throws IOException { - String headers[][] = { + String[][] headers = { {"size", "100"}, {"size", "200"}, {"size", "300"}, @@ -100,7 +100,7 @@ public class HeaderPatternRuleTest extends AbstractRuleTestCase assertEquals("abba1", _response.getHeader("title1")); } - private void assertHeaders(String headers[][]) throws IOException + private void assertHeaders(String[][] headers) throws IOException { for (String[] header : headers) { diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRuleTest.java index 52851f5a92a..194646f6c6f 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/HeaderRegexRuleTest.java @@ -43,7 +43,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase public void testHeaderWithTextValues() throws IOException { // different keys - String headers[][] = + String[][] headers = { {"hnum#1", "test1"}, {"hnum#2", "2test2"}, @@ -55,7 +55,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase @Test public void testHeaderWithNumberValues() throws IOException { - String headers[][] = + String[][] headers = { {"hello", "1"}, {"hello", "-1"}, @@ -72,7 +72,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase @Test public void testHeaderOverwriteValues() throws IOException { - String headers[][] = + String[][] headers = { {"size", "100"}, {"size", "200"}, @@ -122,7 +122,7 @@ public class HeaderRegexRuleTest extends AbstractRuleTestCase assertEquals(null, _response.getHeader("cache-control")); } - private void assertHeaders(String headers[][]) throws IOException + private void assertHeaders(String[][] headers) throws IOException { for (String[] header : headers) { diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java index 4977d6a5425..0f817b14e56 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/RewritePatternRuleTest.java @@ -37,7 +37,7 @@ public class RewritePatternRuleTest extends AbstractRuleTestCase {"/foo/bar", "/foo/bar", "/replace"}, {"/foo/bar.txt", "*.txt", "/replace"}, {"/foo/bar/%20x", "/foo/*", "/replace/bar/%20x"}, - }; + }; private RewritePatternRule _rule; @BeforeEach diff --git a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java index 0274fb5fbd5..edf64b1b01d 100644 --- a/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java +++ b/jetty-rewrite/src/test/java/org/eclipse/jetty/rewrite/handler/ValidUrlRuleTest.java @@ -119,7 +119,9 @@ public class ValidUrlRuleTest extends AbstractRuleTestCase // space assertTrue(_rule.isValidChar("\u0020".charAt(0))); // form feed + //@checkstyle-disable-check : IllegalTokenText assertFalse(_rule.isValidChar("\u000c".charAt(0))); + //@checkstyle-enable-check : IllegalTokenText } } diff --git a/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java b/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java index 36e3d4d6cc6..67140ff6d70 100644 --- a/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java +++ b/jetty-security/src/test/java/org/eclipse/jetty/security/ConstraintTest.java @@ -1708,7 +1708,7 @@ public class ConstraintTest { request.login("admin", "fail"); } - catch (ServletException se) + catch (ServletException e) { request.login("admin", "password"); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java index 529515ab381..096bc9e6395 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/AbstractSessionCache.java @@ -723,8 +723,8 @@ public abstract class AbstractSessionCache extends ContainerLifeCycle implements LOG.debug("Checking for idle {}", session.getId()); try (Lock s = session.lock()) { - if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy()) - && session.isValid() && session.isResident() && session.getRequests() <= 0) + if (getEvictionPolicy() > 0 && session.isIdleLongerThan(getEvictionPolicy()) && + session.isValid() && session.isResident() && session.getRequests() <= 0) { //Be careful with saveOnInactiveEviction - you may be able to re-animate a session that was //being managed on another node and has expired. diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java index 87ce36a86f2..89857621904 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/session/SessionHandler.java @@ -18,8 +18,6 @@ package org.eclipse.jetty.server.session; -import static java.lang.Math.round; - import java.io.IOException; import java.util.Arrays; import java.util.Collections; @@ -65,6 +63,8 @@ import org.eclipse.jetty.util.thread.Locker.Lock; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.Scheduler; +import static java.lang.Math.round; + /** * SessionHandler. */ @@ -237,8 +237,8 @@ public class SessionHandler extends ScopedHandler // Do we need to refresh the cookie? if (isUsingCookies() && (s.isIdChanged() || - (getSessionCookieConfig().getMaxAge() > 0 && getRefreshCookieAge() > 0 - && ((now - s.getCookieSetTime())/1000 > getRefreshCookieAge())))) + (getSessionCookieConfig().getMaxAge() > 0 && getRefreshCookieAge() > 0 && + ((now - s.getCookieSetTime()) / 1000 > getRefreshCookieAge())))) { HttpCookie cookie = getSessionCookie(session, _context == null ? "/" : (_context.getContextPath()), secure); s.cookieSet(); @@ -847,8 +847,8 @@ public class SessionHandler extends ScopedHandler public void setSessionIdPathParameterName(String param) { _sessionIdPathParameterName = (param == null || "none".equals(param)) ? null : param; - _sessionIdPathParameterNamePrefix = (param == null || "none".equals(param)) ? - null : (";" + _sessionIdPathParameterName + "="); + _sessionIdPathParameterNamePrefix = (param == null || "none".equals(param)) + ? null : (";" + _sessionIdPathParameterName + "="); } /** @@ -1023,7 +1023,7 @@ public class SessionHandler extends ScopedHandler sessionTrackingModes.size() > 1 && sessionTrackingModes.contains(SessionTrackingMode.SSL)) { - throw new IllegalArgumentException ("sessionTrackingModes specifies a combination of SessionTrackingMode.SSL with a session tracking mode other than SessionTrackingMode.SSL"); + throw new IllegalArgumentException("sessionTrackingModes specifies a combination of SessionTrackingMode.SSL with a session tracking mode other than SessionTrackingMode.SSL"); } _sessionTrackingModes = new HashSet<>(sessionTrackingModes); _usingCookies = _sessionTrackingModes.contains(SessionTrackingMode.COOKIE); @@ -1294,8 +1294,8 @@ public class SessionHandler extends ScopedHandler //most efficient if it can be done as a bulk operation to eg reduce //roundtrips to the persistent store. Only do this if the HouseKeeper that //does the scavenging is configured to actually scavenge - if (_sessionIdManager.getSessionHouseKeeper() != null - && _sessionIdManager.getSessionHouseKeeper().getIntervalSec() > 0) + if (_sessionIdManager.getSessionHouseKeeper() != null && + _sessionIdManager.getSessionHouseKeeper().getIntervalSec() > 0) { _candidateSessionIdsForExpiry.add(session.getId()); if (LOG.isDebugEnabled()) @@ -1525,9 +1525,9 @@ public class SessionHandler extends ScopedHandler { HttpCookie cookie = access(existingSession, request.isSecure()); // Handle changed ID or max-age refresh, but only if this is not a redispatched request - if ((cookie != null) - && (request.getDispatcherType() == DispatcherType.ASYNC - || request.getDispatcherType() == DispatcherType.REQUEST)) + if ((cookie != null) && + (request.getDispatcherType() == DispatcherType.ASYNC || + request.getDispatcherType() == DispatcherType.REQUEST)) baseRequest.getResponse().replaceCookie(cookie); } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java index f88d9c81260..ce95a87b203 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AbstractHttpTest.java @@ -86,11 +86,11 @@ public abstract class AbstractHttpTest HttpTester.Input input = HttpTester.from(socket.getInputStream()); HttpTester.parseResponse(input, response); - if (httpVersion.is("HTTP/1.1") - && response.isComplete() - && response.get("content-length") == null - && response.get("transfer-encoding") == null - && !__noBodyCodes.contains(response.getStatus())) + if (httpVersion.is("HTTP/1.1") && + response.isComplete() && + response.get("content-length") == null && + response.get("transfer-encoding") == null && + !__noBodyCodes.contains(response.getStatus())) assertThat("If HTTP/1.1 response doesn't contain transfer-encoding or content-length headers, " + "it should contain connection:close", response.get("connection"), is("close")); return response; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java index eaeb0f53a8a..a2adea34bb8 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/AsyncStressTest.java @@ -70,7 +70,7 @@ public class AsyncStressTest {"/path?suspend=", "TIMEOUT"}, {"/path?suspend=60000&resume=", "RESUMED"}, {"/path?suspend=60000&complete=", "COMPLETED"}, - }; + }; @BeforeEach public void init() throws Exception diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java index cd1c346c5a3..60c12ac9c90 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/CheckReverseProxyHeadersTest.java @@ -41,10 +41,7 @@ public class CheckReverseProxyHeadersTest // Classic ProxyPass from example.com:80 to localhost:8080 testRequest("Host: localhost:8080\n" + "X-Forwarded-For: 10.20.30.40\n" + - "X-Forwarded-Host: example.com", new RequestValidator() - { - @Override - public void validate(HttpServletRequest request) + "X-Forwarded-Host: example.com", request -> { assertEquals("example.com", request.getServerName()); assertEquals(80, request.getServerPort()); @@ -53,16 +50,12 @@ public class CheckReverseProxyHeadersTest assertEquals("example.com", request.getHeader("Host")); assertEquals("http", request.getScheme()); assertFalse(request.isSecure()); - } - }); + }); // IPv6 ProxyPass from example.com:80 to localhost:8080 testRequest("Host: localhost:8080\n" + "X-Forwarded-For: 10.20.30.40\n" + - "X-Forwarded-Host: [::1]", new RequestValidator() - { - @Override - public void validate(HttpServletRequest request) + "X-Forwarded-Host: [::1]", request -> { assertEquals("[::1]", request.getServerName()); assertEquals(80, request.getServerPort()); @@ -71,16 +64,12 @@ public class CheckReverseProxyHeadersTest assertEquals("[::1]", request.getHeader("Host")); assertEquals("http", request.getScheme()); assertFalse(request.isSecure()); - } - }); + }); // IPv6 ProxyPass from example.com:80 to localhost:8080 testRequest("Host: localhost:8080\n" + "X-Forwarded-For: 10.20.30.40\n" + - "X-Forwarded-Host: [::1]:8888", new RequestValidator() - { - @Override - public void validate(HttpServletRequest request) + "X-Forwarded-Host: [::1]:8888", request -> { assertEquals("[::1]", request.getServerName()); assertEquals(8888, request.getServerPort()); @@ -89,18 +78,14 @@ public class CheckReverseProxyHeadersTest assertEquals("[::1]:8888", request.getHeader("Host")); assertEquals("http", request.getScheme()); assertFalse(request.isSecure()); - } - }); + }); // ProxyPass from example.com:81 to localhost:8080 testRequest("Host: localhost:8080\n" + "X-Forwarded-For: 10.20.30.40\n" + "X-Forwarded-Host: example.com:81\n" + "X-Forwarded-Server: example.com\n" + - "X-Forwarded-Proto: https", new RequestValidator() - { - @Override - public void validate(HttpServletRequest request) + "X-Forwarded-Proto: https", request -> { assertEquals("example.com", request.getServerName()); assertEquals(81, request.getServerPort()); @@ -109,18 +94,15 @@ public class CheckReverseProxyHeadersTest assertEquals("example.com:81", request.getHeader("Host")); assertEquals("https", request.getScheme()); assertTrue(request.isSecure()); - } - }); + + }); // Multiple ProxyPass from example.com:80 to rp.example.com:82 to localhost:8080 testRequest("Host: localhost:8080\n" + "X-Forwarded-For: 10.20.30.40, 10.0.0.1\n" + "X-Forwarded-Host: example.com, rp.example.com:82\n" + "X-Forwarded-Server: example.com, rp.example.com\n" + - "X-Forwarded-Proto: https, http", new RequestValidator() - { - @Override - public void validate(HttpServletRequest request) + "X-Forwarded-Proto: https, http", request -> { assertEquals("example.com", request.getServerName()); assertEquals(443, request.getServerPort()); @@ -129,8 +111,7 @@ public class CheckReverseProxyHeadersTest assertEquals("example.com", request.getHeader("Host")); assertEquals("https", request.getScheme()); assertTrue(request.isSecure()); - } - }); + }); } private void testRequest(String headers, RequestValidator requestValidator) throws Exception diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java index 036781f945c..aa8fb8390aa 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorCloseTestBase.java @@ -59,10 +59,9 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture final CountDownLatch latch = new CountDownLatch(requestCount); configureServer(new HelloWorldHandler()); - URI uri = _server.getURI(); - Socket client = newSocket(uri.getHost(), uri.getPort()); - try + + try (Socket client = newSocket(uri.getHost(), uri.getPort())) { OutputStream os = client.getOutputStream(); @@ -119,10 +118,6 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture reader.setDone(); runner.join(); } - finally - { - client.close(); - } } private int iterations(int cnt) @@ -136,8 +131,8 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture configureServer(new EchoHandler()); URI uri = _server.getURI(); - Socket client = newSocket(uri.getHost(), uri.getPort()); - try + + try (Socket client = newSocket(uri.getHost(), uri.getPort())) { OutputStream os = client.getOutputStream(); @@ -181,10 +176,6 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture String in = reader.getResponse().toString(); assertTrue(in.indexOf(__content.substring(__length - 64)) > 0); } - finally - { - client.close(); - } } public class ResponseReader implements Runnable @@ -226,11 +217,9 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture count = doRead(); } } - catch (IOException ex) - { - } - catch (InterruptedException ex) + catch (IOException | InterruptedException e) { + // ignore } finally { @@ -240,6 +229,7 @@ public abstract class ConnectorCloseTestBase extends HttpServerTestFixture } catch (IOException e) { + // ignore } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java index c76836c3dac..92b876f0803 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ConnectorTimeoutTest.java @@ -392,22 +392,15 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture os.write("\r\n".getBytes("utf-8")); os.flush(); } - catch (Exception e) - { - } + long duration = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start; assertThat(duration, greaterThan(500L)); - try - { - // read the response - String response = IO.toString(is); - assertThat(response, startsWith("HTTP/1.1 500 ")); - assertThat(response, containsString("InterruptedIOException")); - } - catch (SSLException e) - { - } + // read the response + String response = IO.toString(is); + assertThat(response, startsWith("HTTP/1.1 500 ")); + assertThat(response, containsString("InterruptedIOException")); + } @Test @@ -499,9 +492,6 @@ public abstract class ConnectorTimeoutTest extends HttpServerTestFixture break; } } - catch (Throwable e) - { - } long end = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); long duration = end - start; assertThat(duration, lessThan(20L * 128L)); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java index a93314daa61..3b365ac95e9 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/GracefulStopTest.java @@ -223,12 +223,13 @@ public class GracefulStopTest { try (Socket s = new Socket("127.0.0.1", port)) { + // no op } throw new IllegalStateException(); } catch (ConnectException e) { - + // no op } // Try another request on existing connection @@ -298,6 +299,7 @@ public class GracefulStopTest } catch (InterruptedException e) { + // no op } finally { diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java index 04dfe7af23e..f2be892780c 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpConnectionTest.java @@ -22,6 +22,7 @@ * To change the template for this generated file go to * Window>Preferences>Java>Code Generation>Code and Comments */ + package org.eclipse.jetty.server; import java.io.BufferedReader; @@ -145,7 +146,7 @@ public class HttpConnectionTest * HTTP/0.9 does not support HttpVersion (this is a bad request) */ @Test - public void testHttp09_NoVersion() throws Exception + public void testHttp09NoVersion() throws Exception { connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616); String request = "GET / HTTP/0.9\r\n\r\n"; @@ -162,7 +163,7 @@ public class HttpConnectionTest * HTTP/0.9 does not support headers */ @Test - public void testHttp09_NoHeaders() throws Exception + public void testHttp09NoHeaders() throws Exception { connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616); // header looking like another request is ignored @@ -176,7 +177,7 @@ public class HttpConnectionTest * Http/0.9 does not support pipelining. */ @Test - public void testHttp09_MultipleRequests() throws Exception + public void testHttp09MultipleRequests() throws Exception { connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616); @@ -193,7 +194,7 @@ public class HttpConnectionTest * Ensure that excessively large hexadecimal chunk body length is parsed properly. */ @Test - public void testHttp11_ChunkedBodyTruncation() throws Exception + public void testHttp11ChunkedBodyTruncation() throws Exception { String request = "POST /?id=123 HTTP/1.1\r\n" + "Host: local\r\n" + @@ -222,10 +223,10 @@ public class HttpConnectionTest * More then 1 Content-Length is a bad requests per HTTP rfcs. */ @Test - public void testHttp11_MultipleContentLength() throws Exception + public void testHttp11MultipleContentLength() throws Exception { HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED..."); - int contentLengths[][] = { + int[][] contentLengths = { {0, 8}, {8, 0}, {8, 8}, @@ -266,10 +267,10 @@ public class HttpConnectionTest * More then 1 Content-Length is a bad requests per HTTP rfcs. */ @Test - public void testHttp11_ContentLengthAndChunk() throws Exception + public void testHttp11ContentLengthAndChunk() throws Exception { HttpParser.LOG.info("badMessage: 400 Bad messages EXPECTED..."); - int contentLengths[][] = { + int[][] contentLengths = { {-1, 8}, {8, -1}, {8, -1, 8}, @@ -403,7 +404,7 @@ public class HttpConnectionTest } @Test - public void test_0_9() throws Exception + public void test09() throws Exception { connector.getConnectionFactory(HttpConnectionFactory.class).setHttpCompliance(HttpCompliance.RFC2616_LEGACY); LocalEndPoint endp = connector.executeRequest("GET /R1\n"); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java index 500c292e0fb..336079e4874 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitBadBehaviourTest.java @@ -46,7 +46,7 @@ import static org.hamcrest.Matchers.is; public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest { - private final String CONTEXT_ATTRIBUTE = getClass().getName() + ".asyncContext"; + private final String contextAttribute = getClass().getName() + ".asyncContext"; public static Stream httpVersions() { @@ -95,7 +95,7 @@ public class HttpManyWaysToAsyncCommitBadBehaviourTest extends AbstractHttpTest return; } - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); new Thread(new Runnable() diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java index 7497a6b554a..ca5ebddc616 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpManyWaysToAsyncCommitTest.java @@ -44,7 +44,7 @@ import static org.hamcrest.Matchers.nullValue; //TODO: add protocol specific tests for connection: close and/or chunking public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest { - private final String CONTEXT_ATTRIBUTE = getClass().getName() + ".asyncContext"; + private final String contextAttribute = getClass().getName() + ".asyncContext"; public static Stream httpVersion() { @@ -101,10 +101,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -164,10 +164,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -227,10 +227,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -301,10 +301,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -377,10 +377,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -453,10 +453,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -533,10 +533,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -610,10 +610,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -688,10 +688,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -761,10 +761,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override @@ -835,10 +835,10 @@ public class HttpManyWaysToAsyncCommitTest extends AbstractHttpTest @Override public void doNonErrorHandle(String target, Request baseRequest, final HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { - if (request.getAttribute(CONTEXT_ATTRIBUTE) == null) + if (request.getAttribute(contextAttribute) == null) { final AsyncContext asyncContext = baseRequest.startAsync(); - request.setAttribute(CONTEXT_ATTRIBUTE, asyncContext); + request.setAttribute(contextAttribute, asyncContext); new Thread(new Runnable() { @Override diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java index 5e804e79c4e..3102db8873d 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/HttpServerTestBase.java @@ -60,14 +60,15 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; public abstract class HttpServerTestBase extends HttpServerTestFixture { private static final String REQUEST1_HEADER = "POST / HTTP/1.0\n" + "Host: localhost\n" + "Content-Type: text/xml; charset=utf-8\n" + "Connection: close\n" + "Content-Length: "; - private static final String REQUEST1_CONTENT = "\n" - + "\n" - + ""; + private static final String REQUEST1_CONTENT = "\n" + + "\n" + + ""; private static final String REQUEST1 = REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT; private static final String RESPONSE1 = "HTTP/1.1 200 OK\n" + "Content-Length: 13\n" + "Server: Jetty(" + Server.getVersion() + ")\n" + "\n" + "Hello world\n"; @@ -102,8 +103,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture " \n" + " 73\n" + " \n" + - " \n" - + "\n"; + " \n" + + "\n"; protected static final String RESPONSE2 = "HTTP/1.1 200 OK\n" + "Content-Type: text/xml;charset=iso-8859-1\n" + @@ -141,10 +142,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture { OutputStream os = client.getOutputStream(); - os.write(("OPTIONS * HTTP/1.1\r\n" - + "Host: " + _serverURI.getHost() + "\r\n" - + "Connection: close\r\n" - + "\r\n").getBytes(StandardCharsets.ISO_8859_1)); + os.write(("OPTIONS * HTTP/1.1\r\n" + + "Host: " + _serverURI.getHost() + "\r\n" + + "Connection: close\r\n" + + "\r\n").getBytes(StandardCharsets.ISO_8859_1)); os.flush(); // Read the response. @@ -158,10 +159,10 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture { OutputStream os = client.getOutputStream(); - os.write(("GET * HTTP/1.1\r\n" - + "Host: " + _serverURI.getHost() + "\r\n" - + "Connection: close\r\n" - + "\r\n").getBytes(StandardCharsets.ISO_8859_1)); + os.write(("GET * HTTP/1.1\r\n" + + "Host: " + _serverURI.getHost() + "\r\n" + + "Connection: close\r\n" + + "\r\n").getBytes(StandardCharsets.ISO_8859_1)); os.flush(); // Read the response. @@ -184,7 +185,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture StacklessLogging stackless = new StacklessLogging(HttpConnection.class)) { client.setSoTimeout(10000); - ((AbstractLogger)Log.getLogger(HttpConnection.class)).info("expect request is too large, then ISE extra data ..."); + Log.getLogger(HttpConnection.class).info("expect request is too large, then ISE extra data ..."); OutputStream os = client.getOutputStream(); byte[] buffer = new byte[64 * 1024]; @@ -433,22 +434,27 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort())) { OutputStream os = client.getOutputStream(); - + //@checkstyle-disable-check : IllegalTokenText os.write(("GET /R2 HTTP/1.1\015\012" + "Host: localhost\015\012" + "Transfer-Encoding: chunked\015\012" + "Content-Type: text/plain\015\012" + "Connection: close\015\012" + "\015\012").getBytes()); + //@checkstyle-enable-check : IllegalTokenText os.flush(); Thread.sleep(1000); os.write(("5").getBytes()); Thread.sleep(1000); + //@checkstyle-disable-check : IllegalTokenText os.write(("\015\012").getBytes()); + //@checkstyle-enable-check : IllegalTokenText os.flush(); Thread.sleep(1000); + //@checkstyle-disable-check : IllegalTokenText os.write(("ABCDE\015\012" + "0;\015\012\015\012").getBytes()); + //@checkstyle-enable-check : IllegalTokenText os.flush(); // Read the response. @@ -465,7 +471,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture try (Socket client = newSocket(_serverURI.getHost(), _serverURI.getPort())) { OutputStream os = client.getOutputStream(); - + //@checkstyle-disable-check : IllegalTokenText os.write(("GET /R2 HTTP/1.1\015\012" + "Host: localhost\015\012" + "Content-Length: 5\015\012" + @@ -474,6 +480,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture "\015\012" + "ABCDE\015\012" + "\015\012" + //@checkstyle-enable-check : IllegalTokenText ).getBytes()); os.flush(); @@ -939,7 +946,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture } // check close - assertTrue(in.readLine() == null); + assertNull(in.readLine()); } } @@ -1127,6 +1134,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture OutputStream os = client.getOutputStream(); InputStream is = client.getInputStream(); + //@checkstyle-disable-check : IllegalTokenText os.write(( "POST /R1 HTTP/1.1\015\012" + "Host: " + _serverURI.getHost() + ":" + _serverURI.getPort() + "\r\n" + @@ -1149,7 +1157,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture "Connection: close\015\012" + "\015\012" + "abcdefghi\n" - + //@checkstyle-enable-check : IllegalTokenText ).getBytes(StandardCharsets.ISO_8859_1)); String in = IO.toString(is); @@ -1281,7 +1289,7 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture client.close(); Thread.sleep(200); - assertTrue(!handler._endp.isOpen()); + assertFalse(handler._endp.isOpen()); } } @@ -1547,8 +1555,8 @@ public abstract class HttpServerTestBase extends HttpServerTestFixture { byte[] bytes = ( "GET / HTTP/1.1\r\n" + - "Host: localhost\r\n" - + "Content-Length: " + cl + "\r\n" + + "Host: localhost\r\n" + + "Content-Length: " + cl + "\r\n" + "\r\n" + content).getBytes(StandardCharsets.ISO_8859_1); diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java index a06fc72e6fc..81c89ae2331 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/LocalAsyncContextTest.java @@ -328,7 +328,7 @@ public class LocalAsyncContextTest final AsyncContext asyncContext = baseRequest.startAsync(); response.getOutputStream().println("STARTASYNC"); - asyncContext.addListener(__asyncListener); + asyncContext.addListener(_asyncListener); if (_suspendFor > 0) asyncContext.setTimeout(_suspendFor); @@ -465,7 +465,7 @@ public class LocalAsyncContextTest } } - private AsyncListener __asyncListener = new AsyncListener() + private AsyncListener _asyncListener = new AsyncListener() { @Override public void onComplete(AsyncEvent event) throws IOException diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/NotAcceptingTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/NotAcceptingTest.java index 16d1b2482a4..38bc9da6fe4 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/NotAcceptingTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/NotAcceptingTest.java @@ -45,7 +45,7 @@ import static org.junit.jupiter.api.Assertions.fail; public class NotAcceptingTest { - private final long IDLE_TIMEOUT = 2000; + private final long idleTimeout = 2000; Server server; LocalConnector localConnector; ServerConnector blockingConnector; @@ -57,18 +57,18 @@ public class NotAcceptingTest server = new Server(); localConnector = new LocalConnector(server); - localConnector.setIdleTimeout(IDLE_TIMEOUT); + localConnector.setIdleTimeout(idleTimeout); server.addConnector(localConnector); blockingConnector = new ServerConnector(server, 1, 1); blockingConnector.setPort(0); - blockingConnector.setIdleTimeout(IDLE_TIMEOUT); + blockingConnector.setIdleTimeout(idleTimeout); blockingConnector.setAcceptQueueSize(10); server.addConnector(blockingConnector); asyncConnector = new ServerConnector(server, 0, 1); asyncConnector.setPort(0); - asyncConnector.setIdleTimeout(IDLE_TIMEOUT); + asyncConnector.setIdleTimeout(idleTimeout); asyncConnector.setAcceptQueueSize(10); server.addConnector(asyncConnector); } @@ -128,7 +128,7 @@ public class NotAcceptingTest try { - uri = handler.exchange.exchange("delayed connection", IDLE_TIMEOUT, TimeUnit.MILLISECONDS); + uri = handler.exchange.exchange("delayed connection", idleTimeout, TimeUnit.MILLISECONDS); fail("Failed near URI: " + uri); // this displays last URI, not current (obviously) } catch (TimeoutException e) @@ -177,7 +177,7 @@ public class NotAcceptingTest { local[i] = client; client.addInputAndExecute(BufferUtil.toBuffer("GET /three HTTP/1.1\r\nHost:localhost\r\n\r\n")); - response = HttpTester.parseResponse(client.getResponse(false, IDLE_TIMEOUT, TimeUnit.MILLISECONDS)); + response = HttpTester.parseResponse(client.getResponse(false, idleTimeout, TimeUnit.MILLISECONDS)); // A few local connections may succeed if (i == local.length - 1) @@ -245,7 +245,7 @@ public class NotAcceptingTest try { - uri = handler.exchange.exchange("delayed connection", IDLE_TIMEOUT, TimeUnit.MILLISECONDS); + uri = handler.exchange.exchange("delayed connection", idleTimeout, TimeUnit.MILLISECONDS); fail(uri); } catch (TimeoutException e) @@ -415,9 +415,9 @@ public class NotAcceptingTest } } - waitFor(localConnector::isAccepting, is(true), 2 * IDLE_TIMEOUT, TimeUnit.MILLISECONDS); - waitFor(blockingConnector::isAccepting, is(true), 2 * IDLE_TIMEOUT, TimeUnit.MILLISECONDS); - waitFor(asyncConnector::isAccepting, is(true), 2 * IDLE_TIMEOUT, TimeUnit.MILLISECONDS); + waitFor(localConnector::isAccepting, is(true), 2 * idleTimeout, TimeUnit.MILLISECONDS); + waitFor(blockingConnector::isAccepting, is(true), 2 * idleTimeout, TimeUnit.MILLISECONDS); + waitFor(asyncConnector::isAccepting, is(true), 2 * idleTimeout, TimeUnit.MILLISECONDS); } public static class HelloHandler extends AbstractHandler @@ -459,6 +459,7 @@ public class NotAcceptingTest } catch (InterruptedException e) { + // no op } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java b/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java index 1724cf39a01..6f598dbc5e2 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/PartialRFC2616Test.java @@ -39,6 +39,7 @@ import static org.hamcrest.Matchers.not; import static org.hamcrest.Matchers.nullValue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class PartialRFC2616Test { @@ -116,10 +117,12 @@ public class PartialRFC2616Test "Host: localhost\n" + "Transfer-Encoding: chunked,identity\n" + "Content-Type: text/plain\n" + + //@checkstyle-disable-check : IllegalTokenText "\015\012" + "5;\015\012" + "123\015\012\015\012" + "0;\015\012\015\012"); + //@checkstyle-enable-check : IllegalTokenText checkContains(response, offset, "HTTP/1.1 400 Bad", "Chunked last"); } @@ -308,8 +311,9 @@ public class PartialRFC2616Test "Content-Type: text/plain\n" + "Content-Length: 5\n" + "\n" + + //@checkstyle-disable-check : IllegalTokenText "123\015\012" + - + //@checkstyle-enable-check : IllegalTokenText "GET /R2 HTTP/1.1\n" + "Host: localhost\n" + "Transfer-Encoding: other\n" + @@ -440,7 +444,9 @@ public class PartialRFC2616Test { int offset = 0; String response = connector.getResponse("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n", 250, TimeUnit.MILLISECONDS); + //@checkstyle-disable-check : IllegalTokenText offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2 default") + 10; + //@checkstyle-enable-check : IllegalTokenText checkContains(response, offset, "Content-Length: ", "8.1.2 default"); LocalEndPoint endp = connector.executeRequest("GET /R1 HTTP/1.1\n" + "Host: localhost\n" + "\n" + @@ -449,12 +455,16 @@ public class PartialRFC2616Test offset = 0; response = endp.getResponse(); + //@checkstyle-disable-check : IllegalTokenText offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2 default") + 1; + //@checkstyle-enable-check : IllegalTokenText offset = checkContains(response, offset, "/R1", "8.1.2 default") + 1; offset = 0; response = endp.getResponse(); + //@checkstyle-disable-check : IllegalTokenText offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "8.1.2.2 pipeline") + 11; + //@checkstyle-enable-check : IllegalTokenText offset = checkContains(response, offset, "Connection: close", "8.1.2.2 pipeline") + 1; offset = checkContains(response, offset, "/R2", "8.1.2.1 close") + 3; @@ -491,7 +501,9 @@ public class PartialRFC2616Test "Content-Length: 8\n" + "Connection: close\n" + "\n" + + //@checkstyle-disable-check : IllegalTokenText "123456\015\012"); + //@checkstyle-enable-check : IllegalTokenText checkNotContained(response, offset, "HTTP/1.1 100 ", "8.2.3 expect 100"); offset = checkContains(response, offset, "HTTP/1.1 200 OK", "8.2.3 expect with body") + 1; } @@ -511,9 +523,9 @@ public class PartialRFC2616Test String infomational = endp.getResponse(); offset = checkContains(infomational, offset, "HTTP/1.1 100 ", "8.2.3 expect 100") + 1; checkNotContained(infomational, offset, "HTTP/1.1 200", "8.2.3 expect 100"); - + //@checkstyle-disable-check : IllegalTokenText endp.addInput("654321\015\012"); - + //@checkstyle-enable-check : IllegalTokenText String response = endp.getResponse(); offset = 0; offset = checkContains(response, offset, "HTTP/1.1 200", "8.2.3 expect 100") + 1; @@ -608,6 +620,7 @@ public class PartialRFC2616Test { int offset = 0; String response = connector.getResponse("GET /R1 HTTP/1.0\n" + "\n"); + //@checkstyle-disable-check : IllegalTokenText offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 default close") + 10; checkNotContained(response, offset, "Connection: close", "19.6.2 not assumed"); @@ -659,7 +672,7 @@ public class PartialRFC2616Test response = endp.getResponse(); offset = checkContains(response, offset, "HTTP/1.1 200 OK\015\012", "19.6.2 Keep-alive 2") + 11; offset = checkContains(response, offset, "/R2", "19.6.2 Keep-alive close") + 3; - + //@checkstyle-enable-check : IllegalTokenText offset = 0; response = endp.getResponse(); assertThat("19.6.2 closed", response, nullValue()); @@ -667,7 +680,7 @@ public class PartialRFC2616Test catch (Exception e) { e.printStackTrace(); - assertTrue(false); + fail(e.getMessage()); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index 69a29dc6b71..522b481fb6a 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -226,15 +226,7 @@ public class RequestTest assertNull(request.getCookies()); assertEquals("", request.getHeader("Name")); assertTrue(request.getHeaders("Name").hasMoreElements()); // empty - try - { - request.getDateHeader("Name"); - assertTrue(false); - } - catch (IllegalArgumentException e) - { - - } + assertThrows(IllegalArgumentException.class, () -> request.getDateHeader("Name")); assertEquals(-1, request.getDateHeader("Other")); return true; } @@ -640,26 +632,26 @@ public class RequestTest } @Test - public void testContentLength_ExceedsMaxInteger() throws Exception + public void testContentLengthExceedsMaxInteger() throws Exception { - final long HUGE_LENGTH = (long) Integer.MAX_VALUE * 10L; + final long HUGE_LENGTH = (long)Integer.MAX_VALUE * 10L; _handler._checker = (request, response) -> - request.getContentLength() == (-1) // per HttpServletRequest javadoc this must return (-1); - && request.getContentLengthLong() == HUGE_LENGTH; + request.getContentLength() == (-1) && // per HttpServletRequest javadoc this must return (-1); + request.getContentLengthLong() == HUGE_LENGTH; //Send a request with encoded form content - String request="POST / HTTP/1.1\r\n"+ - "Host: whatever\r\n"+ - "Content-Type: application/octet-stream\n"+ - "Content-Length: " + HUGE_LENGTH + "\n"+ - "Connection: close\n"+ - "\n"+ + String request = "POST / HTTP/1.1\r\n" + + "Host: whatever\r\n" + + "Content-Type: application/octet-stream\n" + + "Content-Length: " + HUGE_LENGTH + "\n" + + "Connection: close\n" + + "\n" + "\n"; System.out.println(request); - String responses=_connector.getResponse(request); + String responses = _connector.getResponse(request); assertThat(responses,startsWith("HTTP/1.1 200")); } @@ -667,25 +659,25 @@ public class RequestTest * The Servlet spec and API cannot parse Content-Length that exceeds Long.MAX_VALUE */ @Test - public void testContentLength_ExceedsMaxLong() throws Exception + public void testContentLengthExceedsMaxLong() throws Exception { - String HUGE_LENGTH = Long.MAX_VALUE + "0"; + String hugeLength = Long.MAX_VALUE + "0"; _handler._checker = (request, response) -> - request.getHeader("Content-Length").equals(HUGE_LENGTH) - && request.getContentLength() == (-1) // per HttpServletRequest javadoc this must return (-1); - && request.getContentLengthLong() == (-1); // exact behavior here not specified in Servlet javadoc + request.getHeader("Content-Length").equals(hugeLength) && + request.getContentLength() == (-1) && // per HttpServletRequest javadoc this must return (-1); + request.getContentLengthLong() == (-1); // exact behavior here not specified in Servlet javadoc //Send a request with encoded form content - String request="POST / HTTP/1.1\r\n"+ - "Host: whatever\r\n"+ - "Content-Type: application/octet-stream\n"+ - "Content-Length: " + HUGE_LENGTH + "\n"+ - "Connection: close\n"+ - "\n"+ + String request = "POST / HTTP/1.1\r\n" + + "Host: whatever\r\n" + + "Content-Type: application/octet-stream\n" + + "Content-Length: " + hugeLength + "\n" + + "Connection: close\n" + + "\n" + "\n"; - String responses=_connector.getResponse(request); + String responses = _connector.getResponse(request); assertThat(responses, startsWith("HTTP/1.1 400")); } @@ -1667,8 +1659,7 @@ public class RequestTest String request = "POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Cookie: other=cookie\r\n" + - "\r\n" - + + "\r\n" + "POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Cookie: name=value\r\n" + @@ -1683,8 +1674,7 @@ public class RequestTest request = "POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Cookie: name=value\r\n" + - "\r\n" - + + "\r\n" + "POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Cookie: \r\n" + @@ -1699,8 +1689,7 @@ public class RequestTest "Host: whatever\r\n" + "Cookie: name=value\r\n" + "Cookie: other=cookie\r\n" + - "\r\n" - + + "\r\n" + "POST / HTTP/1.1\r\n" + "Host: whatever\r\n" + "Cookie: name=value\r\n" + @@ -1727,11 +1716,11 @@ public class RequestTest buf.append("a=b"); // The evil keys file is not distributed - as it is dangerous - File evil_keys = new File("/tmp/keys_mapping_to_zero_2m"); - if (evil_keys.exists()) + File evilKeys = new File("/tmp/keys_mapping_to_zero_2m"); + if (evilKeys.exists()) { // Using real evil keys! - try (BufferedReader in = new BufferedReader(new FileReader(evil_keys))) + try (BufferedReader in = new BufferedReader(new FileReader(evilKeys))) { String key = null; while ((key = in.readLine()) != null) @@ -1879,9 +1868,9 @@ public class RequestTest { ((Request)request).setHandled(true); - if (request.getContentLength() > 0 - && !request.getContentType().startsWith(MimeTypes.Type.FORM_ENCODED.asString()) - && !request.getContentType().startsWith("multipart/form-data")) + if (request.getContentLength() > 0 && + !request.getContentType().startsWith(MimeTypes.Type.FORM_ENCODED.asString()) && + !request.getContentType().startsWith("multipart/form-data")) _content = IO.toString(request.getInputStream()); if (_checker != null && _checker.check(request, response)) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServletRequestWrapperTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServletRequestWrapperTest.java index 1d3a757a9d3..b40e5325df5 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServletRequestWrapperTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServletRequestWrapperTest.java @@ -18,17 +18,17 @@ package org.eclipse.jetty.server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - +import java.io.IOException; import javax.servlet.AsyncContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletRequestWrapper; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import java.io.IOException; + +import org.eclipse.jetty.server.handler.AbstractHandler; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java index e948feb1ae7..5e4938d35d3 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/StressTest.java @@ -89,7 +89,7 @@ public class StressTest "/path/d", "/path/e", "/path/f", - }; + }; @BeforeAll public static void init() throws Exception diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerGetResourceTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerGetResourceTest.java index 7f4d9aaa2e1..39ef4c070a3 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerGetResourceTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/ContextHandlerGetResourceTest.java @@ -40,6 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.junit.jupiter.api.Assumptions.assumeTrue; @@ -138,23 +139,8 @@ public class ContextHandlerGetResourceTest public void testBadPath() throws Exception { final String path = "bad"; - try - { - context.getResource(path); - fail("Expected " + MalformedURLException.class); - } - catch (MalformedURLException e) - { - } - - try - { - context.getServletContext().getResource(path); - fail("Expected " + MalformedURLException.class); - } - catch (MalformedURLException e) - { - } + assertThrows(MalformedURLException.class,() -> context.getResource(path)); + assertThrows(MalformedURLException.class,() -> context.getServletContext().getResource(path)); } @Test diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/InetAccessHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/InetAccessHandlerTest.java index 474ac109521..1e2970ead4e 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/InetAccessHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/InetAccessHandlerTest.java @@ -169,7 +169,7 @@ public class InetAccessHandlerTest {"127.0.0.1-127.0.0.254", "", "", "nothttp", "200"}, {"192.0.0.1", "", "", "nothttp", "403"}, {"192.0.0.1-192.0.0.254", "", "", "nothttp", "403"}, - }; + }; return Arrays.asList(data).stream().map(Arguments::of); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java index 4f119ff97fd..6964b7c9ef9 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/handler/NcsaRequestLogTest.java @@ -625,7 +625,7 @@ public class NcsaRequestLogTest } } - private static abstract class AbstractTestHandler extends AbstractHandler + private abstract static class AbstractTestHandler extends AbstractHandler { @Override public String toString() diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionHandlerTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionHandlerTest.java index 817b26b2954..351ede0d227 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionHandlerTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/session/SessionHandlerTest.java @@ -26,7 +26,6 @@ import javax.servlet.SessionTrackingMode; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; - public class SessionHandlerTest { @Test diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java index 3c802b3b529..fe3589007b6 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SSLEngineTest.java @@ -254,6 +254,7 @@ public class SSLEngineTest } catch (SocketException e) { + // no op } } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java index 688dc8bcfa4..5c68b9ef802 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ssl/SniSslConnectionFactoryTest.java @@ -73,7 +73,7 @@ public class SniSslConnectionFactoryTest { private Server _server; private ServerConnector _connector; - private HttpConfiguration _https_config; + private HttpConfiguration _httpsConfiguration; private int _port; @BeforeEach @@ -85,11 +85,11 @@ public class SniSslConnectionFactoryTest http_config.setSecureScheme("https"); http_config.setSecurePort(8443); http_config.setOutputBufferSize(32768); - _https_config = new HttpConfiguration(http_config); + _httpsConfiguration = new HttpConfiguration(http_config); SecureRequestCustomizer src = new SecureRequestCustomizer(); src.setSniHostCheck(true); - _https_config.addCustomizer(src); - _https_config.addCustomizer((connector, httpConfig, request) -> + _httpsConfiguration.addCustomizer(src); + _httpsConfiguration.addCustomizer((connector, httpConfig, request) -> { EndPoint endp = request.getHttpChannel().getEndPoint(); if (endp instanceof SslConnection.DecryptedEndPoint) @@ -126,7 +126,7 @@ public class SniSslConnectionFactoryTest ServerConnector https = _connector = new ServerConnector(_server, new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()), - new HttpConnectionFactory(_https_config)); + new HttpConnectionFactory(_httpsConfiguration)); _server.addConnector(https); _server.setHandler(new AbstractHandler.ErrorDispatchHandler() diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java index 5b41d82917e..19ce7db825d 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/DefaultServletTest.java @@ -2120,6 +2120,7 @@ public class DefaultServletTest } catch (InvalidPathException | IOException ignore) { + // ignore } assumeTrue(ret != null, "Directory creation not supported on OS: " + path + File.separator + subpath); diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java index e80296a0479..899cc3d0169 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ErrorPageTest.java @@ -225,6 +225,7 @@ public class ErrorPageTest } catch (Throwable ignore) { + // no opEchoSocket } } } diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/HolderTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/HolderTest.java index b5cb054cf01..d29eb5baa67 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/HolderTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/HolderTest.java @@ -45,11 +45,11 @@ import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; /** - * @version $Rev$ $Date$ + * */ public class HolderTest { @@ -59,44 +59,19 @@ public class HolderTest { ServletHolder holder = new ServletHolder(Source.JAVAX_API); ServletRegistration reg = holder.getRegistration(); - try - { - reg.setInitParameter(null, "foo"); - fail("null name accepted"); - } - catch (IllegalArgumentException e) - { - } - try - { - reg.setInitParameter("foo", null); - fail("null value accepted"); - } - catch (IllegalArgumentException e) - { - } + + assertThrows(IllegalArgumentException.class,() -> reg.setInitParameter(null, "foo")); + + assertThrows(IllegalArgumentException.class,() -> reg.setInitParameter("foo", null)); + reg.setInitParameter("foo", "bar"); assertFalse(reg.setInitParameter("foo", "foo")); Set clash = reg.setInitParameters(Collections.singletonMap("foo", "bax")); assertTrue(clash != null && clash.size() == 1, "should be one clash"); - try - { - reg.setInitParameters(Collections.singletonMap((String)null, "bax")); - fail("null name in map accepted"); - } - catch (IllegalArgumentException e) - { - } - try - { - reg.setInitParameters(Collections.singletonMap("foo", (String)null)); - fail("null value in map accepted"); - } - catch (IllegalArgumentException e) - { - } + assertThrows(IllegalArgumentException.class,() -> reg.setInitParameters(Collections.singletonMap((String)null, "bax"))); + assertThrows(IllegalArgumentException.class,() -> reg.setInitParameters(Collections.singletonMap("foo", (String)null))); Set clash2 = reg.setInitParameters(Collections.singletonMap("FOO", "bax")); assertTrue(clash2.isEmpty(), "should be no clash"); diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java index ecbbb70a3dc..c4d4c650b57 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/PostServletTest.java @@ -68,18 +68,18 @@ public class PostServletTest len = request.getInputStream().read(buffer); } } - catch (Exception e0) + catch (Exception e) { - ex0.set(e0); + ex0.set(e); try { // this read-call should fail immediately request.getInputStream().read(buffer); } - catch (Exception e1) + catch (Exception ex) { - ex1.set(e1); - LOG.warn(e1.toString()); + ex1.set(ex); + LOG.warn(ex.toString()); } } finally diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java index d1f4b6c9bfb..beb3c2dcdf0 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletContextHandlerTest.java @@ -18,17 +18,6 @@ package org.eclipse.jetty.servlet; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsString; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - import java.io.IOException; import java.io.PrintWriter; import java.util.ArrayList; @@ -84,6 +73,17 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + public class ServletContextHandlerTest { private Server _server; @@ -119,15 +119,8 @@ public class ServletContextHandlerTest { super.doStart(); //call the SCI - try - { - _ctx.setExtendedListenerTypes(true); - _sci.onStartup(Collections.emptySet(), _ctx); - } - finally - { - - } + _ctx.setExtendedListenerTypes(true); + _sci.onStartup(Collections.emptySet(), _ctx); } } @@ -268,8 +261,8 @@ public class ServletContextHandlerTest public static class MySListener implements HttpSessionListener { - public static int creates = 0; - public static int destroys = 0; + public static int creates = 0; + public static int destroys = 0; @Override public void sessionCreated(HttpSessionEvent se) @@ -309,8 +302,7 @@ public class ServletContextHandlerTest ++replaces; } } - - + public static class MySIListener implements HttpSessionIdListener { public static int changes = 0; @@ -485,7 +477,7 @@ public class ServletContextHandlerTest StringBuffer request = new StringBuffer(); request.append("GET /test?session=replace HTTP/1.0\n"); request.append("Host: localhost\n"); - request.append("Cookie: "+sessionid+"\n"); + request.append("Cookie: " + sessionid + "\n"); request.append("\n"); response = _connector.getResponse(request.toString()); assertThat(response, Matchers.containsString("200 OK")); @@ -496,7 +488,7 @@ public class ServletContextHandlerTest request = new StringBuffer(); request.append("GET /test?session=remove HTTP/1.0\n"); request.append("Host: localhost\n"); - request.append("Cookie: "+sessionid+"\n"); + request.append("Cookie: " + sessionid + "\n"); request.append("\n"); response = _connector.getResponse(request.toString()); assertThat(response, Matchers.containsString("200 OK")); @@ -509,7 +501,7 @@ public class ServletContextHandlerTest request = new StringBuffer(); request.append("GET /test?session=change HTTP/1.0\n"); request.append("Host: localhost\n"); - request.append("Cookie: "+sessionid+"\n"); + request.append("Cookie: " + sessionid + "\n"); request.append("\n"); response = _connector.getResponse(request.toString()); assertThat(response, Matchers.containsString("200 OK")); @@ -520,7 +512,7 @@ public class ServletContextHandlerTest request = new StringBuffer(); request.append("GET /test?session=delete HTTP/1.0\n"); request.append("Host: localhost\n"); - request.append("Cookie: "+sessionid+"\n"); + request.append("Cookie: " + sessionid + "\n"); request.append("\n"); response = _connector.getResponse(request.toString()); assertThat(response, Matchers.containsString("200 OK")); @@ -1025,8 +1017,6 @@ public class ServletContextHandlerTest //change and remove context attribute req.getServletContext().setAttribute("foo", "foo"); req.getServletContext().removeAttribute("foo"); - - return; } } } diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java index 1f8ad1a8f05..06a4d4c3933 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletHolderTest.java @@ -108,9 +108,9 @@ public class ServletHolderTest { assertThat(e.getMessage(), containsString("foo")); } - catch (MultiException m) + catch (MultiException e) { - assertThat(m.getCause().getMessage(), containsString("foo")); + assertThat(e.getCause().getMessage(), containsString("foo")); } } @@ -132,9 +132,9 @@ public class ServletHolderTest { assertThat(e.getMessage(), containsString("foo")); } - catch (MultiException m) + catch (MultiException e) { - assertThat(m.getCause().getMessage(), containsString("foo")); + assertThat(e.getCause().getMessage(), containsString("foo")); } } } diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletRequestLogTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletRequestLogTest.java index 68dc5871e54..cbe4617c2a3 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletRequestLogTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletRequestLogTest.java @@ -83,7 +83,7 @@ public class ServletRequestLogTest } @SuppressWarnings("serial") - private static abstract class AbstractTestServlet extends HttpServlet + private abstract static class AbstractTestServlet extends HttpServlet { @Override public String toString() diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletTester.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletTester.java index 3e10f1530b7..90fe3bf170a 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletTester.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/ServletTester.java @@ -244,9 +244,9 @@ public class ServletTester extends ContainerLifeCycle else connector.open(); - return "http://" + (localhost ? "127.0.0.1" : - InetAddress.getLocalHost().getHostAddress() - ) + ":" + connector.getLocalPort(); + return "http://" + (localhost ? "127.0.0.1" + : InetAddress.getLocalHost().getHostAddress()) + + ":" + connector.getLocalPort(); } public LocalConnector createLocalConnector() diff --git a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java index eb23aa14b99..d653969c274 100644 --- a/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java +++ b/jetty-servlet/src/test/java/org/eclipse/jetty/servlet/StatisticsServletTest.java @@ -128,7 +128,8 @@ public class StatisticsServletTest public static class Stats { - int responses2xx, responses4xx; + int responses2xx; + int responses4xx; public Stats(int responses2xx, int responses4xx) { diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultNoRecompressTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultNoRecompressTest.java index 8d68bfdf9fa..3c4cae449a0 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultNoRecompressTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultNoRecompressTest.java @@ -42,7 +42,7 @@ public class GzipDefaultNoRecompressTest { public static Stream data() { - return Arrays.asList(new Object[][] + return Arrays.stream(new Object[][] { // Some already compressed files {"test_quotes.gz", "application/gzip", GzipHandler.GZIP}, @@ -64,7 +64,7 @@ public class GzipDefaultNoRecompressTest //qvalue disables compression {"test_quotes.txt", "text/plain", GzipHandler.GZIP + ";q=0"}, {"test_quotes.txt", "text/plain", GzipHandler.GZIP + "; q = 0 "}, - }).stream().map(Arguments::of); + }).map(Arguments::of); } public WorkDir testingdir; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java index 1b5d89e34e0..5f0a14c44cf 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/GzipDefaultTest.java @@ -101,10 +101,10 @@ public class GzipDefaultTest @SuppressWarnings("serial") public static class HttpContentTypeWithEncoding extends HttpServlet { - public static final String COMPRESSED_CONTENT = "

COMPRESSABLE CONTENT

" - + "This content must be longer than the default min gzip length, which is 256 bytes. " - + "The moon is blue to a fish in love. How now brown cow. The quick brown fox jumped over the lazy dog. A woman needs a man like a fish needs a bicycle!" - + ""; + public static final String COMPRESSED_CONTENT = "

COMPRESSABLE CONTENT

" + + "This content must be longer than the default min gzip length, which is 256 bytes. " + + "The moon is blue to a fish in love. How now brown cow. The quick brown fox jumped over the lazy dog. A woman needs a man like a fish needs a bicycle!" + + ""; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/Hex.java b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/Hex.java index 9366b7b9631..3b2d7cfc3b1 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/Hex.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/server/handler/gzip/Hex.java @@ -57,7 +57,7 @@ public final class Hex return buf; } - public static String asHex(byte buf[]) + public static String asHex(byte[] buf) { int len = buf.length; char[] out = new char[len * 2]; diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java index 93cdb81c7bf..4ae31b94e8a 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/AbstractDoSFilterTest.java @@ -341,6 +341,7 @@ public abstract class AbstractDoSFilterTest } catch (InterruptedException e) { + // no op } } @@ -358,6 +359,7 @@ public abstract class AbstractDoSFilterTest } catch (InterruptedException e) { + // no op } } } diff --git a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java index f7ee299a895..1933b45935b 100644 --- a/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java +++ b/jetty-servlets/src/test/java/org/eclipse/jetty/servlets/QoSFilterTest.java @@ -58,9 +58,9 @@ public class QoSFilterTest private ServletTester _tester; private LocalConnector[] _connectors; - private final int NUM_CONNECTIONS = 8; - private final int NUM_LOOPS = 6; - private final int MAX_QOS = 4; + private final int numConnections = 8; + private final int numLoops = 6; + private final int maxQos = 4; @BeforeEach public void setUp() throws Exception @@ -71,7 +71,7 @@ public class QoSFilterTest TestServlet.__maxSleepers = 0; TestServlet.__sleepers = 0; - _connectors = new LocalConnector[NUM_CONNECTIONS]; + _connectors = new LocalConnector[numConnections]; for (int i = 0; i < _connectors.length; ++i) { _connectors[i] = _tester.createLocalConnector(); @@ -90,20 +90,20 @@ public class QoSFilterTest public void testNoFilter() throws Exception { List workers = new ArrayList<>(); - for (int i = 0; i < NUM_CONNECTIONS; ++i) + for (int i = 0; i < numConnections; ++i) { workers.add(new Worker(i)); } - ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS); + ExecutorService executor = Executors.newFixedThreadPool(numConnections); List> futures = executor.invokeAll(workers, 10, TimeUnit.SECONDS); rethrowExceptions(futures); - if (TestServlet.__maxSleepers <= MAX_QOS) + if (TestServlet.__maxSleepers <= maxQos) LOG.warn("TEST WAS NOT PARALLEL ENOUGH!"); else - assertThat(TestServlet.__maxSleepers, Matchers.lessThanOrEqualTo(NUM_CONNECTIONS)); + assertThat(TestServlet.__maxSleepers, Matchers.lessThanOrEqualTo(numConnections)); } @Disabled("Issue #2627") @@ -112,24 +112,24 @@ public class QoSFilterTest { FilterHolder holder = new FilterHolder(QoSFilter2.class); holder.setAsyncSupported(true); - holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, "" + MAX_QOS); + holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, "" + maxQos); _tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC)); List workers = new ArrayList<>(); - for (int i = 0; i < NUM_CONNECTIONS; ++i) + for (int i = 0; i < numConnections; ++i) { workers.add(new Worker(i)); } - ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS); + ExecutorService executor = Executors.newFixedThreadPool(numConnections); List> futures = executor.invokeAll(workers, 10, TimeUnit.SECONDS); rethrowExceptions(futures); - if (TestServlet.__maxSleepers < MAX_QOS) + if (TestServlet.__maxSleepers < maxQos) LOG.warn("TEST WAS NOT PARALLEL ENOUGH!"); else - assertEquals(TestServlet.__maxSleepers, MAX_QOS); + assertEquals(TestServlet.__maxSleepers, maxQos); } @Test @@ -137,24 +137,24 @@ public class QoSFilterTest { FilterHolder holder = new FilterHolder(QoSFilter2.class); holder.setAsyncSupported(true); - holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, String.valueOf(MAX_QOS)); + holder.setInitParameter(QoSFilter.MAX_REQUESTS_INIT_PARAM, String.valueOf(maxQos)); _tester.getContext().getServletHandler().addFilterWithMapping(holder, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ASYNC)); List workers = new ArrayList<>(); - for (int i = 0; i < NUM_CONNECTIONS; ++i) + for (int i = 0; i < numConnections; ++i) { workers.add(new Worker2(i)); } - ExecutorService executor = Executors.newFixedThreadPool(NUM_CONNECTIONS); + ExecutorService executor = Executors.newFixedThreadPool(numConnections); List> futures = executor.invokeAll(workers, 20, TimeUnit.SECONDS); rethrowExceptions(futures); - if (TestServlet.__maxSleepers < MAX_QOS) + if (TestServlet.__maxSleepers < maxQos) LOG.warn("TEST WAS NOT PARALLEL ENOUGH!"); else - assertEquals(TestServlet.__maxSleepers, MAX_QOS); + assertEquals(TestServlet.__maxSleepers, maxQos); } private void rethrowExceptions(List> futures) throws Exception @@ -177,7 +177,7 @@ public class QoSFilterTest @Override public Void call() throws Exception { - for (int i = 0; i < NUM_LOOPS; i++) + for (int i = 0; i < numLoops; i++) { HttpTester.Request request = HttpTester.newRequest(); @@ -211,7 +211,7 @@ public class QoSFilterTest try { String addr = _tester.createConnector(true); - for (int i = 0; i < NUM_LOOPS; i++) + for (int i = 0; i < numLoops; i++) { url = new URL(addr + "/context/test?priority=" + (_num % QoSFilter.DEFAULT_MAX_PRIORITY) + "&n=" + _num + "&l=" + i); url.getContent(); diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersAbsoluteTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersAbsoluteTest.java index 058ff74f735..4c72eda881e 100755 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersAbsoluteTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersAbsoluteTest.java @@ -43,7 +43,9 @@ public class PathMatchersAbsoluteTest arguments.add(Arguments.of("/opt/florb", true)); arguments.add(Arguments.of("/home/user/benfranklin", true)); arguments.add(Arguments.of("glob:/home/user/benfranklin/*.jar", true)); + //@checkstyle-disable-check : LegacyMethodSeparators arguments.add(Arguments.of("glob:/**/*.jar", true)); + //@checkstyle-enable-check : LegacyMethodSeparators arguments.add(Arguments.of("regex:/*-[^dev].ini", true)); } diff --git a/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersSearchRootTest.java b/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersSearchRootTest.java index eb20189bf93..15ee9ba81c9 100644 --- a/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersSearchRootTest.java +++ b/jetty-start/src/test/java/org/eclipse/jetty/start/PathMatchersSearchRootTest.java @@ -41,7 +41,9 @@ public class PathMatchersSearchRootTest { // absolute first arguments.add(Arguments.of("/opt/app/*.jar", "/opt/app")); + //@checkstyle-disable-check : LegacyMethodSeparators arguments.add(Arguments.of("/lib/jvm/**/jre/lib/*.jar", "/lib/jvm")); + //@checkstyle-enable-check : LegacyMethodSeparators arguments.add(Arguments.of("glob:/var/lib/*.xml", "/var/lib")); arguments.add(Arguments.of("glob:/var/lib/*.{xml,java}", "/var/lib")); arguments.add(Arguments.of("glob:/opt/corporate/lib-{dev,prod}/*.ini", "/opt/corporate")); diff --git a/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketClient.java b/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketClient.java index 6a184a29cfa..3c2fdb14655 100644 --- a/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketClient.java +++ b/jetty-unixsocket/src/test/java/org/eclipse/jetty/unixsocket/UnixSocketClient.java @@ -45,11 +45,11 @@ public class UnixSocketClient body = IO.readToString(content); content_length = body.length(); } - String data = method + " / HTTP/1.1\r\n" - + "Host: unixsock\r\n" - + "Content-Length: " + content_length + "\r\n" - + "Connection: close\r\n" - + "\r\n"; + String data = method + " / HTTP/1.1\r\n" + + "Host: unixsock\r\n" + + "Content-Length: " + content_length + "\r\n" + + "Connection: close\r\n" + + "\r\n"; if (body != null) data += body; diff --git a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java index e14abbe6320..0eb8742584b 100644 --- a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java +++ b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorFactoryTest.java @@ -45,13 +45,13 @@ public class JSONPojoConvertorFactoryTest Foo foo = new Foo(); foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; - foo._int2 = new Integer(2); - foo._long1 = 1000001l; - foo._long2 = new Long(1000002l); + foo._int2 = Integer.valueOf(2); + foo._long1 = 1000001L; + foo._long2 = Long.valueOf(1000002L); foo._float1 = 10.11f; - foo._float2 = new Float(10.22f); + foo._float2 = Float.valueOf(10.22f); foo._double1 = 10000.11111d; - foo._double2 = new Double(10000.22222d); + foo._double2 = Double.valueOf(10000.22222d); Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo), new Baz[]{ new Baz("baz0", Boolean.TRUE, null), new Baz("baz1", Boolean.FALSE, null) @@ -91,13 +91,13 @@ public class JSONPojoConvertorFactoryTest Foo foo = new Foo(); foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; - foo._int2 = new Integer(2); - foo._long1 = 1000001l; - foo._long2 = new Long(1000002l); + foo._int2 = Integer.valueOf(2); + foo._long1 = 1000001L; + foo._long2 = Long.valueOf(1000002L); foo._float1 = 10.11f; - foo._float2 = new Float(10.22f); + foo._float2 = Float.valueOf(10.22f); foo._double1 = 10000.11111d; - foo._double2 = new Double(10000.22222d); + foo._double2 = Double.valueOf(10000.22222d); Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo), new Baz[]{ new Baz("baz0", Boolean.TRUE, null), new Baz("baz1", Boolean.FALSE, null) @@ -134,7 +134,8 @@ public class JSONPojoConvertorFactoryTest public static class Bar { - private String _title, _nullTest; + private String _title; + private String _nullTest; private Baz _baz; private boolean _boolean1; private Baz[] _bazs; @@ -328,15 +329,15 @@ public class JSONPojoConvertorFactoryTest if (another instanceof Foo) { Foo foo = (Foo)another; - return getName().equals(foo.getName()) - && getInt1() == foo.getInt1() - && getInt2().equals(foo.getInt2()) - && getLong1() == foo.getLong1() - && getLong2().equals(foo.getLong2()) - && getFloat1() == foo.getFloat1() - && getFloat2().equals(foo.getFloat2()) - && getDouble1() == foo.getDouble1() - && getDouble2().equals(foo.getDouble2()); + return getName().equals(foo.getName()) && + getInt1() == foo.getInt1() && + getInt2().equals(foo.getInt2()) && + getLong1() == foo.getLong1() && + getLong2().equals(foo.getLong2()) && + getFloat1() == foo.getFloat1() && + getFloat2().equals(foo.getFloat2()) && + getDouble1() == foo.getDouble1() && + getDouble2().equals(foo.getDouble2()); } return false; diff --git a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java index aa56ccd95fe..ea9cab24990 100644 --- a/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java +++ b/jetty-util-ajax/src/test/java/org/eclipse/jetty/util/ajax/JSONPojoConvertorTest.java @@ -44,15 +44,15 @@ public class JSONPojoConvertorTest Foo foo = new Foo(); foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; - foo._int2 = new Integer(2); - foo._long1 = 1000001l; - foo._long2 = new Long(1000002l); + foo._int2 = Integer.valueOf(2); + foo._long1 = 1000001L; + foo._long2 = Long.valueOf(1000002L); foo._float1 = 10.11f; - foo._float2 = new Float(10.22f); + foo._float2 = Float.valueOf(10.22f); foo._double1 = 10000.11111d; - foo._double2 = new Double(10000.22222d); + foo._double2 = Double.valueOf(10000.22222d); foo._char1 = 'a'; - foo._char2 = new Character('b'); + foo._char2 = Character.valueOf('b'); Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo), new Baz[]{ new Baz("baz0", Boolean.TRUE, null), new Baz("baz1", Boolean.FALSE, null) @@ -92,15 +92,15 @@ public class JSONPojoConvertorTest Foo foo = new Foo(); foo._name = "Foo @ " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); foo._int1 = 1; - foo._int2 = new Integer(2); - foo._long1 = 1000001l; - foo._long2 = new Long(1000002l); + foo._int2 = Integer.valueOf(2); + foo._long1 = 1000001L; + foo._long2 = Long.valueOf(1000002L); foo._float1 = 10.11f; - foo._float2 = new Float(10.22f); + foo._float2 = Float.valueOf(10.22f); foo._double1 = 10000.11111d; - foo._double2 = new Double(10000.22222d); + foo._double2 = Double.valueOf(10000.22222d); foo._char1 = 'a'; - foo._char2 = new Character('b'); + foo._char2 = Character.valueOf('b'); Bar bar = new Bar("Hello", true, new Baz("World", Boolean.FALSE, foo)); // bar.setColor(Color.Blue); @@ -135,7 +135,8 @@ public class JSONPojoConvertorTest public static class Bar { - private String _title, _nullTest; + private String _title; + private String _nullTest; private Baz _baz; private boolean _boolean1; private Baz[] _bazs; @@ -334,17 +335,17 @@ public class JSONPojoConvertorTest if (another instanceof Foo) { Foo foo = (Foo)another; - return getName().equals(foo.getName()) - && getInt1() == foo.getInt1() - && getInt2().equals(foo.getInt2()) - && getLong1() == foo.getLong1() - && getLong2().equals(foo.getLong2()) - && getFloat1() == foo.getFloat1() - && getFloat2().equals(foo.getFloat2()) - && getDouble1() == foo.getDouble1() - && getDouble2().equals(foo.getDouble2()) - && getChar1() == foo.getChar1() - && getChar2().equals(foo.getChar2()); + return getName().equals(foo.getName()) && + getInt1() == foo.getInt1() && + getInt2().equals(foo.getInt2()) && + getLong1() == foo.getLong1() && + getLong2().equals(foo.getLong2()) && + getFloat1() == foo.getFloat1() && + getFloat2().equals(foo.getFloat2()) && + getDouble1() == foo.getDouble1() && + getDouble2().equals(foo.getDouble2()) && + getChar1() == foo.getChar1() && + getChar2().equals(foo.getChar2()); } return false; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java index 49fdd144a6d..e1fb7e615e5 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/BufferUtilTest.java @@ -42,7 +42,7 @@ public class BufferUtilTest @Test public void testToInt() throws Exception { - ByteBuffer buf[] = + ByteBuffer[] buf = { BufferUtil.toBuffer("0"), BufferUtil.toBuffer(" 42 "), @@ -51,9 +51,9 @@ public class BufferUtilTest BufferUtil.toBuffer(" - 45;"), BufferUtil.toBuffer("-2147483648"), BufferUtil.toBuffer("2147483647"), - }; + }; - int val[] = + int[] val = { 0, 42, 43, -44, -45, -2147483648, 2147483647 }; @@ -67,12 +67,12 @@ public class BufferUtilTest @Test public void testPutInt() throws Exception { - int val[] = + int[] val = { 0, 42, 43, -44, -45, Integer.MIN_VALUE, Integer.MAX_VALUE }; - String str[] = + String[] str = { "0", "42", "43", "-44", "-45", "" + Integer.MIN_VALUE, "" + Integer.MAX_VALUE }; @@ -91,12 +91,12 @@ public class BufferUtilTest @Test public void testPutLong() throws Exception { - long val[] = + long[] val = { 0L, 42L, 43L, -44L, -45L, Long.MIN_VALUE, Long.MAX_VALUE }; - String str[] = + String[] str = { "0", "42", "43", "-44", "-45", "" + Long.MIN_VALUE, "" + Long.MAX_VALUE }; @@ -115,12 +115,12 @@ public class BufferUtilTest @Test public void testPutHexInt() throws Exception { - int val[] = + int[] val = { 0, 42, 43, -44, -45, -2147483648, 2147483647 }; - String str[] = + String[] str = { "0", "2A", "2B", "-2C", "-2D", "-80000000", "7FFFFFFF" }; diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java index 093ce3a56cb..e24e81118bc 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/FutureCallbackTest.java @@ -28,8 +28,10 @@ import org.hamcrest.Matchers; import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -49,14 +51,7 @@ public class FutureCallbackTest FutureCallback fcb = new FutureCallback(); long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - try - { - fcb.get(500, TimeUnit.MILLISECONDS); - fail("Expected a TimeoutException"); - } - catch (TimeoutException e) - { - } + assertThrows(TimeoutException.class, () -> fcb.get(500, TimeUnit.MILLISECONDS)); assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.greaterThan(50L)); } @@ -79,22 +74,18 @@ public class FutureCallbackTest final FutureCallback fcb = new FutureCallback(); final CountDownLatch latch = new CountDownLatch(1); - new Thread(new Runnable() + new Thread(() -> { - @Override - public void run() + latch.countDown(); + try { - latch.countDown(); - try - { - TimeUnit.MILLISECONDS.sleep(100); - } - catch (Exception e) - { - e.printStackTrace(); - } - fcb.succeeded(); + TimeUnit.MILLISECONDS.sleep(100); } + catch (Exception e) + { + e.printStackTrace(); + } + fcb.succeeded(); }).start(); latch.await(); @@ -117,15 +108,9 @@ public class FutureCallbackTest assertFalse(fcb.isCancelled()); long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - try - { - fcb.get(); - fail("Expected an ExecutionException"); - } - catch (ExecutionException ee) - { - assertEquals(ex, ee.getCause()); - } + ExecutionException e = assertThrows(ExecutionException.class, () -> fcb.get()); + assertEquals(ex, e.getCause()); + assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(100L)); } @@ -136,35 +121,24 @@ public class FutureCallbackTest final Exception ex = new Exception("FAILED"); final CountDownLatch latch = new CountDownLatch(1); - new Thread(new Runnable() + new Thread(() -> { - @Override - public void run() + latch.countDown(); + try { - latch.countDown(); - try - { - TimeUnit.MILLISECONDS.sleep(100); - } - catch (Exception e) - { - e.printStackTrace(); - } - fcb.failed(ex); + TimeUnit.MILLISECONDS.sleep(100); } + catch (Exception e) + { + e.printStackTrace(); + } + fcb.failed(ex); }).start(); latch.await(); long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - try - { - fcb.get(10000, TimeUnit.MILLISECONDS); - fail("Expected an ExecutionException"); - } - catch (ExecutionException ee) - { - assertEquals(ex, ee.getCause()); - } + ExecutionException e = assertThrows(ExecutionException.class, () -> fcb.get(10000, TimeUnit.MILLISECONDS)); + assertEquals(ex, e.getCause()); assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.greaterThan(10L)); assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(5000L)); @@ -181,15 +155,8 @@ public class FutureCallbackTest assertTrue(fcb.isCancelled()); long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - try - { - fcb.get(); - fail("Expected a CancellationException"); - } - catch (CancellationException e) - { - assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class)); - } + CancellationException e = assertThrows(CancellationException.class, () -> fcb.get()); + assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class)); assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(100L)); } @@ -199,35 +166,25 @@ public class FutureCallbackTest final FutureCallback fcb = new FutureCallback(); final CountDownLatch latch = new CountDownLatch(1); - new Thread(new Runnable() + new Thread(() -> { - @Override - public void run() + latch.countDown(); + try { - latch.countDown(); - try - { - TimeUnit.MILLISECONDS.sleep(100); - } - catch (Exception e) - { - e.printStackTrace(); - } - fcb.cancel(true); + TimeUnit.MILLISECONDS.sleep(100); } + catch (Exception e) + { + e.printStackTrace(); + } + fcb.cancel(true); }).start(); latch.await(); long start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - try - { - fcb.get(10000, TimeUnit.MILLISECONDS); - fail("Expected a CancellationException"); - } - catch (CancellationException e) - { - assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class)); - } + CancellationException e = assertThrows(CancellationException.class,() -> fcb.get(10000, TimeUnit.MILLISECONDS)); + assertThat(e.getCause(), Matchers.instanceOf(CancellationException.class)); + assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.greaterThan(10L)); assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, Matchers.lessThan(1000L)); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java index b69e7d730aa..72a182cb4df 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/InetAddressSetTest.java @@ -82,7 +82,7 @@ public class InetAddressSetTest "[::1", "[xxx]", "[:::1]", - }; + }; InetAddressSet set = new InetAddressSet(); @@ -159,7 +159,7 @@ public class InetAddressSetTest "255.255.8.0/16", "255.255.8.1/17", "[::1]/129", - }; + }; InetAddressSet set = new InetAddressSet(); @@ -214,7 +214,7 @@ public class InetAddressSetTest { "10.0.0.0-9.0.0.0", "9.0.0.0-[::10.0.0.0]", - }; + }; InetAddressSet set = new InetAddressSet(); @@ -266,7 +266,7 @@ public class InetAddressSetTest "9.0-10.0", "10.0.0--1.1", "10.0.0-256.1", - }; + }; InetAddressSet set = new InetAddressSet(); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/RolloverFileOutputStreamTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/RolloverFileOutputStreamTest.java index fd88b1441ea..26cb2415185 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/RolloverFileOutputStreamTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/RolloverFileOutputStreamTest.java @@ -94,7 +94,7 @@ public class RolloverFileOutputStreamTest ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate); assertThat("Midnight", toString(midnight), is("2017.04.27-12:00:00.0 AM PDT")); - Object expected[][] = { + Object[][] expected = { {"2017.04.27-12:00:00.0 AM PDT", 14_400_000L}, {"2017.04.28-12:00:00.0 AM PDT", 86_400_000L}, {"2017.04.29-12:00:00.0 AM PDT", 86_400_000L}, @@ -115,7 +115,7 @@ public class RolloverFileOutputStreamTest ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate); assertThat("Midnight", toString(midnight), is("2016.03.11-12:00:00.0 AM PST")); - Object expected[][] = { + Object[][] expected = { {"2016.03.12-12:00:00.0 AM PST", 86_400_000L}, {"2016.03.13-12:00:00.0 AM PST", 86_400_000L}, {"2016.03.14-12:00:00.0 AM PDT", 82_800_000L}, // the short day @@ -135,7 +135,7 @@ public class RolloverFileOutputStreamTest ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate); assertThat("Midnight", toString(midnight), is("2016.11.04-12:00:00.0 AM PDT")); - Object expected[][] = { + Object[][] expected = { {"2016.11.05-12:00:00.0 AM PDT", 86_400_000L}, {"2016.11.06-12:00:00.0 AM PDT", 86_400_000L}, {"2016.11.07-12:00:00.0 AM PST", 90_000_000L}, // the long day @@ -155,7 +155,7 @@ public class RolloverFileOutputStreamTest ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate); assertThat("Midnight", toString(midnight), is("2016.10.01-12:00:00.0 AM AEST")); - Object expected[][] = { + Object[][] expected = { {"2016.10.02-12:00:00.0 AM AEST", 86_400_000L}, {"2016.10.03-12:00:00.0 AM AEDT", 82_800_000L}, // the short day {"2016.10.04-12:00:00.0 AM AEDT", 86_400_000L}, @@ -175,7 +175,7 @@ public class RolloverFileOutputStreamTest ZonedDateTime midnight = RolloverFileOutputStream.toMidnight(initialDate); assertThat("Midnight", toString(midnight), is("2016.04.02-12:00:00.0 AM AEDT")); - Object expected[][] = { + Object[][] expected = { {"2016.04.03-12:00:00.0 AM AEDT", 86_400_000L}, {"2016.04.04-12:00:00.0 AM AEST", 90_000_000L}, // The long day {"2016.04.05-12:00:00.0 AM AEST", 86_400_000L}, diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java index 9124e468b7a..3f230703d1b 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/SharedBlockingCallbackTest.java @@ -123,10 +123,10 @@ public class SharedBlockingCallbackTest } fail("Should have thrown IOException"); } - catch (IOException ee) + catch (IOException e) { start = TimeUnit.NANOSECONDS.toMillis(System.nanoTime()); - assertEquals(ex, ee.getCause()); + assertEquals(ex, e.getCause()); } assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, lessThan(100L)); assertEquals(0, notComplete.get()); @@ -168,9 +168,9 @@ public class SharedBlockingCallbackTest } fail("Should have thrown IOException"); } - catch (IOException ee) + catch (IOException e) { - assertEquals(ex, ee.getCause()); + assertEquals(ex, e.getCause()); } assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, greaterThan(10L)); assertThat(TimeUnit.NANOSECONDS.toMillis(System.nanoTime()) - start, lessThan(1000L)); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java index 7e3ff50bdee..f34e4c42b74 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/StringUtilTest.java @@ -204,7 +204,9 @@ public class StringUtilTest assertThat(StringUtil.indexOfControlChars("\t"), is(0)); assertThat(StringUtil.indexOfControlChars(";\n"), is(1)); assertThat(StringUtil.indexOfControlChars("abc\fz"), is(3)); + //@checkstyle-disable-check : IllegalTokenText assertThat(StringUtil.indexOfControlChars("z\010"), is(1)); + //@checkstyle-enable-check : IllegalTokenText assertThat(StringUtil.indexOfControlChars(":\u001c"), is(1)); assertThat(StringUtil.indexOfControlChars(null), is(-1)); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java index 0cbce822b2b..49a94520987 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java @@ -114,7 +114,7 @@ public class URIUtilCanonicalPathTest // paths with encoded segments should remain encoded // canonicalPath() is not responsible for decoding characters {"%2e%2e/", "%2e%2e/"}, - }; + }; ArrayList ret = new ArrayList<>(); for (String[] args : canonical) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java index a517404d97a..c69e6298f96 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URLEncodedTest.java @@ -167,7 +167,7 @@ public class URLEncodedTest {StringUtil.__ISO_8859_1, StringUtil.__ISO_8859_1, "%30"}, {StringUtil.__UTF8, StringUtil.__UTF8, "%30"}, {StringUtil.__UTF16, StringUtil.__UTF16, "%00%30"}, - }; + }; // Note: "%30" -> decode -> "0" diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java index 5f0167ec211..0a1184bc49e 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java @@ -375,9 +375,8 @@ public class ContainerLifeCycleTest child.add(c); } - public @Override - String toString() + public String toString() { return "listener"; } @@ -385,18 +384,16 @@ public class ContainerLifeCycleTest ContainerLifeCycle c0 = new ContainerLifeCycle() { - public @Override - String toString() + public String toString() { return "c0"; } }; ContainerLifeCycle c00 = new ContainerLifeCycle() { - public @Override - String toString() + public String toString() { return "c00"; } @@ -437,9 +434,8 @@ public class ContainerLifeCycleTest child.add(c); } - public @Override - String toString() + public String toString() { return "inherited"; } @@ -526,27 +522,24 @@ public class ContainerLifeCycleTest { ContainerLifeCycle c0 = new ContainerLifeCycle() { - public @Override - String toString() + public String toString() { return "c0"; } }; ContainerLifeCycle c00 = new ContainerLifeCycle() { - public @Override - String toString() + public String toString() { return "c00"; } }; ContainerLifeCycle c01 = new ContainerLifeCycle() { - public @Override - String toString() + public String toString() { return "c01"; } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerNestedTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerNestedTest.java index 18f475ab8e7..05842671974 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerNestedTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/LifeCycleListenerNestedTest.java @@ -37,7 +37,7 @@ import static org.hamcrest.Matchers.is; public class LifeCycleListenerNestedTest { // Set this true to use test-specific workaround. - private final boolean WORKAROUND = false; + private final boolean workaround = false; public static class Foo extends ContainerLifeCycle { @@ -186,7 +186,7 @@ public class LifeCycleListenerNestedTest CapturingListener listener = new CapturingListener(); foo.addLifeCycleListener(listener); - if (WORKAROUND) + if (workaround) foo.addEventListener(listener); try @@ -217,7 +217,7 @@ public class LifeCycleListenerNestedTest CapturingListener listener = new CapturingListener(); foo.addLifeCycleListener(listener); - if (WORKAROUND) + if (workaround) foo.addEventListener(listener); Bar bara = new Bar("a"); @@ -255,7 +255,7 @@ public class LifeCycleListenerNestedTest CapturingListener listener = new CapturingListener(); foo.addLifeCycleListener(listener); - if (WORKAROUND) + if (workaround) foo.addEventListener(listener); try diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java index 45b34334c82..0dfd45ed883 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/log/StdErrLogTest.java @@ -726,19 +726,25 @@ public class StdErrLogTest Exception inner = new Exception("inner"); inner.addSuppressed(new IllegalStateException() - {{ - addSuppressed(new Exception("branch0")); - }}); + { + { + addSuppressed(new Exception("branch0")); + } + }); IOException outer = new IOException("outer", inner); outer.addSuppressed(new IllegalStateException() - {{ - addSuppressed(new Exception("branch1")); - }}); + { + { + addSuppressed(new Exception("branch1")); + } + }); outer.addSuppressed(new IllegalArgumentException() - {{ - addSuppressed(new Exception("branch2")); - }}); + { + { + addSuppressed(new Exception("branch2")); + } + }); log.warn("problem", outer); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java index 9fa220d6402..cf79bf1dc76 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java @@ -336,6 +336,7 @@ public class FileSystemResourceTest } catch (Exception e) { + // FIXME why ignoring exceptions?? } } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/CounterStatisticTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/CounterStatisticTest.java index 82d1971ea77..2449aa54620 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/CounterStatisticTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/CounterStatisticTest.java @@ -89,10 +89,7 @@ public class CounterStatisticTest for (int i = N; i-- > 0; ) { threads[i] = (i >= N / 2) - ? new Thread() - { - @Override - public void run() + ? new Thread(() -> { try { @@ -110,12 +107,9 @@ public class CounterStatisticTest if (random.nextInt(5) == 0) Thread.yield(); } - } - } - : new Thread() - { - @Override - public void run() + }) + + : new Thread(() -> { try { @@ -134,8 +128,7 @@ public class CounterStatisticTest if (random.nextInt(5) == 0) Thread.yield(); } - } - }; + }); threads[i].start(); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java index 9f48c5a76d0..51907ec22b2 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/statistic/SampleStatisticTest.java @@ -35,15 +35,15 @@ public class SampleStatisticTest 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 100, 90, 110, 95, 105, 97, 103 }, - }; + }; private static double[][] results = - { /* {mean,stddev}*/ - {100.0, 0.0}, - {100.0, Math.sqrt((10 * 10 + 10 * 10) / 12.0)}, - {100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 14.0)}, - {100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 24.0)}, - {100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 104.0)} + /* {mean,stddev}*/ + {{100.0, 0.0}, + {100.0, Math.sqrt((10 * 10 + 10 * 10) / 12.0)}, + {100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 14.0)}, + {100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 24.0)}, + {100.0, Math.sqrt((10 * 10 + 10 * 10 + 5 * 5 + 5 * 5 + 3 * 3 + 3 * 3) / 104.0)} }; @Test diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java index 7d81923a5dd..71e0d58569c 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/AbstractThreadPoolTest.java @@ -44,7 +44,7 @@ public abstract class AbstractThreadPoolTest ProcessorUtils.setAvailableProcessors(originalCoreCount); } - abstract protected SizedThreadPool newPool(int max); + protected abstract SizedThreadPool newPool(int max); @Test public void testBudget_constructMaxThenLease() diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java index c96c6a6cd31..edcd78a8137 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/QueuedThreadPoolTest.java @@ -466,6 +466,7 @@ public class QueuedThreadPoolTest extends AbstractThreadPoolTest } catch (InterruptedException expected) { + // no op } } }); diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java index aedbe1bce1c..b165909dec3 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/SchedulerTest.java @@ -70,6 +70,7 @@ public class SchedulerTest } catch (Exception ignore) { + // no op } }); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/strategy/ExecutionStrategyTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/strategy/ExecutionStrategyTest.java index bfbe0a3991f..0c0af510c67 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/thread/strategy/ExecutionStrategyTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/thread/strategy/ExecutionStrategyTest.java @@ -78,7 +78,7 @@ public class ExecutionStrategyTest _threads.stop(); } - public static abstract class TestProducer implements Producer + public abstract static class TestProducer implements Producer { @Override public String toString() @@ -122,14 +122,7 @@ public class ExecutionStrategyTest { if (tasks-- > 0) { - return new Runnable() - { - @Override - public void run() - { - latch.countDown(); - } - }; + return () -> latch.countDown(); } return null; @@ -175,15 +168,7 @@ public class ExecutionStrategyTest try { final CountDownLatch latch = q.take(); - return new Runnable() - { - @Override - public void run() - { - // System.err.println("RUN "+id); - latch.countDown(); - } - }; + return () -> latch.countDown(); } catch (InterruptedException e) { diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index d840420d9c5..501c5c0996f 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -605,6 +605,7 @@ public class WebAppClassLoader extends URLClassLoader implements ClassVisibility * @param name the name of the class to load * @param checkSystemResource if true and the class isn't a system class we return it * @return the loaded class + * @throws ClassNotFoundException if the class cannot be found */ protected Class loadAsResource(final String name, boolean checkSystemResource) throws ClassNotFoundException { diff --git a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java index 352301503c5..358612ee419 100644 --- a/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java +++ b/jetty-webapp/src/test/java/org/eclipse/jetty/webapp/WebAppContextTest.java @@ -407,9 +407,6 @@ public class WebAppContextTest } history.add(e.getMessage()); } - finally - { - } } assertThat(history, contains("I0", "I1", "I2", "Listener2 init broken", "D1", "D0", "Listener1 destroy broken")); diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java index 1a66eae99f8..e811792f22e 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/MessageReceivingTest.java @@ -59,13 +59,13 @@ public class MessageReceivingTest private static EchoHandler handler; private static URI serverUri; private WebSocketContainer container; - private final String VERY_LONG_STRING; + private final String veryLongString; public MessageReceivingTest() { byte[] raw = new byte[1024 * 1024]; Arrays.fill(raw, (byte)'x'); - VERY_LONG_STRING = new String(raw, StandardCharsets.UTF_8); + veryLongString = new String(raw, StandardCharsets.UTF_8); } @BeforeAll @@ -137,7 +137,7 @@ public class MessageReceivingTest LOG.debug("Client Connected: {}", session); session.getBasicRemote().sendText(""); session.getBasicRemote().sendText("Echo"); - session.getBasicRemote().sendText(VERY_LONG_STRING); + session.getBasicRemote().sendText(veryLongString); session.getBasicRemote().sendText("Echo"); if (LOG.isDebugEnabled()) LOG.debug("Client Message Sent"); @@ -232,7 +232,7 @@ public class MessageReceivingTest /** * Abstract message handler implementation, used for tests. */ - private static abstract class AbstractHandler implements MessageHandler + private abstract static class AbstractHandler implements MessageHandler { /** * Message queue to put the result messages. diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/ClientAnnotatedEndpointScanner_GoodSignaturesTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/ClientAnnotatedEndpointScanner_GoodSignaturesTest.java index f9421e3054a..04a27dd9125 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/ClientAnnotatedEndpointScanner_GoodSignaturesTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/endpoints/ClientAnnotatedEndpointScanner_GoodSignaturesTest.java @@ -142,7 +142,7 @@ public class ClientAnnotatedEndpointScanner_GoodSignaturesTest // The JsrAnnotatedMetadata field that should be populated Field metadataField; // The expected parameters for the Callable found by the scanner - Class expectedParameters[]; + Class[] expectedParameters; public Scenario(Class pojo, Field metadataField, Class... expectedParams) { diff --git a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/utils/ReflectUtilsTest.java b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/utils/ReflectUtilsTest.java index 9a2729d6757..b18f3c778f4 100644 --- a/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/utils/ReflectUtilsTest.java +++ b/jetty-websocket/javax-websocket-client-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/utils/ReflectUtilsTest.java @@ -39,15 +39,15 @@ public class ReflectUtilsTest { } - public static abstract class Apple implements Fruit, Color + public abstract static class Apple implements Fruit, Color { } - public static abstract class Cherry implements Fruit, Color + public abstract static class Cherry implements Fruit, Color { } - public static abstract class Banana implements Fruit, Color + public abstract static class Banana implements Fruit, Color { } diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java index 4136d3b48f4..90600bf3c47 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ConfiguratorTest.java @@ -299,20 +299,20 @@ public class ConfiguratorTest public static class GmtTimeDecoder implements Decoder.Text { - private TimeZone TZ; + private TimeZone timeZone; @Override public Calendar decode(String s) throws DecodeException { - if (TZ == null) + if (timeZone == null) throw new DecodeException(s, ".init() not called"); try { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss"); - dateFormat.setTimeZone(TZ); + dateFormat.setTimeZone(timeZone); Date time = dateFormat.parse(s); Calendar cal = Calendar.getInstance(); - cal.setTimeZone(TZ); + cal.setTimeZone(timeZone); cal.setTime(time); return cal; } @@ -325,7 +325,7 @@ public class ConfiguratorTest @Override public void init(EndpointConfig config) { - TZ = TimeZone.getTimeZone("GMT+0"); + timeZone = TimeZone.getTimeZone("GMT+0"); } @Override @@ -346,7 +346,7 @@ public class ConfiguratorTest decoders = {GmtTimeDecoder.class}) public static class TimeDecoderSocket { - private TimeZone TZ = TimeZone.getTimeZone("GMT+0"); + private TimeZone timeZone = TimeZone.getTimeZone("GMT+0"); @OnMessage public String onMessage(Calendar cal) @@ -357,7 +357,7 @@ public class ConfiguratorTest private SimpleDateFormat newDateFormat() { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd G 'at' HH:mm:ss Z", Locale.ENGLISH); - dateFormat.setTimeZone(TZ); + dateFormat.setTimeZone(timeZone); return dateFormat; } } diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java index b8a8702e16e..d9b5e1ad1cb 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/DelayedStartClientOnServerTest.java @@ -179,8 +179,8 @@ public class DelayedStartClientOnServerTest if (threadName.startsWith("HttpClient@") && !threadName.endsWith("-scheduler")) { throw new AssertionError("Found non-scheduler HttpClient thread in <" + - threadNames.stream().collect(Collectors.joining("[", ", ", "]")) - + ">"); + threadNames.stream().collect(Collectors.joining("[", ", ", "]")) + + ">"); } } } diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ExtensionStackProcessingTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ExtensionStackProcessingTest.java index cd26f244c54..6af44c1407c 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ExtensionStackProcessingTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ExtensionStackProcessingTest.java @@ -100,7 +100,7 @@ public class ExtensionStackProcessingTest assumeDeflateFrameAvailable(); ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .extensions(Arrays.asList(new JsrExtension("deflate-frame"))) + .extensions(Arrays.asList(new JsrExtension("deflate-frame"))) .build(); final String content = "deflate_me"; @@ -129,14 +129,7 @@ public class ExtensionStackProcessingTest assertTrue(thirdOut instanceof WebSocketClientConnection); final CountDownLatch latch = new CountDownLatch(1); - session.getAsyncRemote().sendText(content, new SendHandler() - { - @Override - public void onResult(SendResult result) - { - latch.countDown(); - } - }); + session.getAsyncRemote().sendText(content, result -> latch.countDown()); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(messageLatch.await(5, TimeUnit.SECONDS)); @@ -148,7 +141,7 @@ public class ExtensionStackProcessingTest assumeDeflateFrameAvailable(); ClientEndpointConfig config = ClientEndpointConfig.Builder.create() - .extensions(Arrays.asList(new JsrExtension("permessage-deflate"))) + .extensions(Arrays.asList(new JsrExtension("permessage-deflate"))) .build(); final String content = "deflate_me"; @@ -165,20 +158,13 @@ public class ExtensionStackProcessingTest }, config, uri); final CountDownLatch latch = new CountDownLatch(1); - session.getAsyncRemote().sendText(content, new SendHandler() - { - @Override - public void onResult(SendResult result) - { - latch.countDown(); - } - }); + session.getAsyncRemote().sendText(content, result -> latch.countDown()); assertTrue(latch.await(5, TimeUnit.SECONDS)); assertTrue(messageLatch.await(5, TimeUnit.SECONDS)); } - private static abstract class EndpointAdapter extends Endpoint implements MessageHandler.Whole + private abstract static class EndpointAdapter extends Endpoint implements MessageHandler.Whole { @Override public void onOpen(Session session, EndpointConfig config) diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/JsrBatchModeTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/JsrBatchModeTest.java index 89bed3f230b..136aa8675a3 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/JsrBatchModeTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/JsrBatchModeTest.java @@ -171,7 +171,7 @@ public class JsrBatchModeTest } } - private static abstract class EndpointAdapter extends Endpoint implements MessageHandler.Whole + private abstract static class EndpointAdapter extends Endpoint implements MessageHandler.Whole { @Override public void onOpen(Session session, EndpointConfig config) diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeNestedClientContainerTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeNestedClientContainerTest.java index 6a5c5403088..ec6d8bb7c4d 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeNestedClientContainerTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/LargeNestedClientContainerTest.java @@ -45,7 +45,7 @@ import static org.hamcrest.Matchers.is; */ public class LargeNestedClientContainerTest { - public static abstract class WSServerConfig + public abstract static class WSServerConfig { private final String description; diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/MemoryUsageTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/MemoryUsageTest.java index adcdd453d28..6ab0f6eeea4 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/MemoryUsageTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/MemoryUsageTest.java @@ -121,7 +121,7 @@ public class MemoryUsageTest assertThat("heap used", heapUsed, lessThan(expected)); } - private static abstract class EndpointAdapter extends Endpoint implements MessageHandler.Whole + private abstract static class EndpointAdapter extends Endpoint implements MessageHandler.Whole { @Override public void onOpen(Session session, EndpointConfig config) diff --git a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java index cc23378c458..9273f4f5ffb 100644 --- a/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java +++ b/jetty-websocket/javax-websocket-server-impl/src/test/java/org/eclipse/jetty/websocket/jsr356/server/ServerAnnotatedEndpointScanner_GoodSignaturesTest.java @@ -178,7 +178,7 @@ public class ServerAnnotatedEndpointScanner_GoodSignaturesTest // The JsrAnnotatedMetadata field that should be populated Field metadataField; // The expected parameters for the Callable found by the scanner - Class expectedParameters[]; + Class[] expectedParameters; public Scenario(Class pojo, Field metadataField, Class... expectedParams) { diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java index 05de848298f..1351290d347 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java @@ -63,7 +63,8 @@ public class ConcurrentConnectTest ServletContextHandler context = new ServletContextHandler(); context.setContextPath("/"); - WebSocketServlet servlet = new WebSocketServlet() { + WebSocketServlet servlet = new WebSocketServlet() + { @Override public void configure(WebSocketServletFactory factory) { diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java index 40a31d0c940..4a3e4153639 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/AbstractCloseEndpoint.java @@ -33,7 +33,7 @@ import static org.hamcrest.Matchers.nullValue; public abstract class AbstractCloseEndpoint extends WebSocketAdapter { - public final Logger LOG; + public final Logger log; public CountDownLatch closeLatch = new CountDownLatch(1); public String closeReason = null; public int closeStatusCode = -1; @@ -41,13 +41,13 @@ public abstract class AbstractCloseEndpoint extends WebSocketAdapter public AbstractCloseEndpoint() { - this.LOG = Log.getLogger(this.getClass().getName()); + this.log = Log.getLogger(this.getClass().getName()); } @Override public void onWebSocketClose(int statusCode, String reason) { - LOG.debug("onWebSocketClose({}, {})", statusCode, reason); + log.debug("onWebSocketClose({}, {})", statusCode, reason); this.closeStatusCode = statusCode; this.closeReason = reason; closeLatch.countDown(); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java index 6f9f3e27eb4..9eeef884b50 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/ContainerEndpoint.java @@ -42,7 +42,7 @@ public class ContainerEndpoint extends AbstractCloseEndpoint @Override public void onWebSocketText(String message) { - LOG.debug("onWebSocketText({})", message); + log.debug("onWebSocketText({})", message); if (message.equalsIgnoreCase("openSessions")) { Collection sessions = container.getOpenSessions(); @@ -62,7 +62,7 @@ public class ContainerEndpoint extends AbstractCloseEndpoint @Override public void onWebSocketConnect(Session sess) { - LOG.debug("onWebSocketConnect({})", sess); + log.debug("onWebSocketConnect({})", sess); this.session = sess; } } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastCloseEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastCloseEndpoint.java index d9d45573502..5309b1ba57b 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastCloseEndpoint.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastCloseEndpoint.java @@ -29,7 +29,7 @@ public class FastCloseEndpoint extends AbstractCloseEndpoint @Override public void onWebSocketConnect(Session sess) { - LOG.debug("onWebSocketConnect({})", sess); + log.debug("onWebSocketConnect({})", sess); sess.close(StatusCode.NORMAL, "FastCloseServer"); } } diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastFailEndpoint.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastFailEndpoint.java index aa2990fc0c8..b6e0cbe6f5e 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastFailEndpoint.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/FastFailEndpoint.java @@ -28,7 +28,7 @@ public class FastFailEndpoint extends AbstractCloseEndpoint @Override public void onWebSocketConnect(Session sess) { - LOG.debug("onWebSocketConnect({})", sess); + log.debug("onWebSocketConnect({})", sess); // Test failure due to unhandled exception // this should trigger a fast-fail closure during open/connect throw new RuntimeException("Intentional FastFail"); diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java index 0a895a8c456..7834e020bff 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/server/PartialListenerTest.java @@ -248,7 +248,6 @@ public class PartialListenerTest } } - public static class PartialCreator implements WebSocketCreator { public PartialEndpoint partialEndpoint; diff --git a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java index c41b536ea9a..a665ce157c9 100644 --- a/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java +++ b/jetty-websocket/websocket-client/src/test/java/org/eclipse/jetty/websocket/client/examples/TestClient.java @@ -246,10 +246,10 @@ public class TestClient long duration = System.currentTimeMillis() - __start; System.out.println("--- " + host + " websocket ping statistics using " + clients + " connection" + (clients > 1 ? "s" : "") + " ---"); System.out.printf("%d/%d frames sent/recv, %d/%d mesg sent/recv, time %dms %dm/s %.2fbps%n", __framesSent, __framesReceived.get(), __messagesSent, - __messagesReceived.get(), duration, ((1000L * __messagesReceived.get()) / duration), (1000.0D * __messagesReceived.get() * 8 * size) - / duration / 1024 / 1024); - System.out.printf("rtt min/ave/max = %.3f/%.3f/%.3f ms\n", __minDuration.get() / 1000000.0, __messagesReceived.get() == 0 ? 0.0 : (__totalTime.get() - / __messagesReceived.get() / 1000000.0), __maxDuration.get() / 1000000.0); + __messagesReceived.get(), duration, ((1000L * __messagesReceived.get()) / duration), (1000.0D * __messagesReceived.get() * 8 * size) / + duration / 1024 / 1024); + System.out.printf("rtt min/ave/max = %.3f/%.3f/%.3f ms\n", __minDuration.get() / 1000000.0, __messagesReceived.get() == 0 ? 0.0 : (__totalTime.get() / + __messagesReceived.get() / 1000000.0), __maxDuration.get() / 1000000.0); wsclient.stop(); } diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java index 7eeeb043465..db94e3c0127 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedBinaryArraySocket.java @@ -31,7 +31,7 @@ public class AnnotatedBinaryArraySocket public EventCapture capture = new EventCapture(); @OnWebSocketMessage - public void onBinary(byte payload[], int offset, int length) + public void onBinary(byte[] payload, int offset, int length) { capture.offer("onBinary([%d],%d,%d)", payload.length, offset, length); } diff --git a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java index 2ebbe705a6e..95081ce6594 100644 --- a/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/examples/AnnotatedStreamingSocket.java @@ -54,7 +54,7 @@ public class AnnotatedStreamingSocket // Binary @OnWebSocketMessage - public void onMessage(byte buf[], int offset, int length) + public void onMessage(byte[] buf, int offset, int length) { } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java index ea4a13b5a82..b2e29c5d85c 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/TextPayloadParserTest.java @@ -143,8 +143,8 @@ public class TextPayloadParserTest String part1 = "Hello "; String part2 = "World"; - byte b1[] = part1.getBytes(StandardCharsets.UTF_8); - byte b2[] = part2.getBytes(StandardCharsets.UTF_8); + byte[] b1 = part1.getBytes(StandardCharsets.UTF_8); + byte[] b2 = part2.getBytes(StandardCharsets.UTF_8); ByteBuffer buf = ByteBuffer.allocate(32); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/BadBinarySignatureSocket.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/BadBinarySignatureSocket.java index d8fe184b464..1b91150a109 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/BadBinarySignatureSocket.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/BadBinarySignatureSocket.java @@ -38,7 +38,7 @@ public class BadBinarySignatureSocket * @return the response boolean */ @OnWebSocketMessage - public boolean onBinary(Session session, byte buf[], int offset, int len) + public boolean onBinary(Session session, byte[] buf, int offset, int len) { return false; } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoBinarySocket.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoBinarySocket.java index 772b0587328..f2aca36b7da 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoBinarySocket.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/annotations/MyEchoBinarySocket.java @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.annotations.WebSocket; public class MyEchoBinarySocket extends MyEchoSocket { @OnWebSocketMessage - public void echoBin(byte buf[], int offset, int length) + public void echoBin(byte[] buf, int offset, int length) { try { diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java index a72d9484536..f0566c7fa16 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/DeflateFrameExtensionTest.java @@ -364,8 +364,11 @@ public class DeflateFrameExtensionTest extends AbstractExtensionTest public void testPyWebSocketServer_Long() { // Captured from PyWebSocket - Long Text (echo from server) - byte[] rawbuf = TypeUtil.fromHexString("c1421cca410a80300c44d1abccce9df7" + "f018298634d05631138ab7b7b8fdef1f" + "dc0282e2061d575a45f6f2686bab25e1" - + "3fb7296fa02b5885eb3b0379c394f461" + "98cafd03"); + byte[] rawbuf = TypeUtil.fromHexString("c1421cca410a80300c44d1abccce9df7" + + "f018298634d05631138ab7b7b8fdef1f" + + "dc0282e2061d575a45f6f2686bab25e1" + + "3fb7296fa02b5885eb3b0379c394f461" + + "98cafd03"); assertIncoming(rawbuf, "It's a big enough umbrella but it's always me that ends up getting wet."); } diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java index 21f8e914dbc..df73b53fec3 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/extensions/compress/PerMessageDeflateExtensionTest.java @@ -138,7 +138,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest tester.assertNegotiated("permessage-deflate"); - tester.parseIncomingHex( // context takeover (2 messages) + tester.parseIncomingHex(// context takeover (2 messages) // message 1 "0xc1 0x07", // (HEADER added for this test) "0xf2 0x48 0xcd 0xc9 0xc9 0x07 0x00", @@ -524,7 +524,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest // Captured from Pywebsocket (r790) - 3 messages with similar parts. - tester.parseIncomingHex( // context takeover (3 messages) + tester.parseIncomingHex(// context takeover (3 messages) "c1 09 0a c9 2f 4a 0c 01 62 00 00", // ToraTora "c1 0b 72 2c c9 2f 4a 74 cb 01 12 00 00", // AtoraFlora "c1 0b 0a c8 c8 c9 2f 4a 0c 01 62 00 00" // PhloraTora @@ -542,7 +542,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest // Captured from Pywebsocket (r790) - "tora" sent 3 times. - tester.parseIncomingHex( // context takeover (3 messages) + tester.parseIncomingHex(// context takeover (3 messages) "c1 06 2a c9 2f 4a 04 00", // tora 1 "c1 05 2a 01 62 00 00", // tora 2 "c1 04 02 61 00 00" // tora 3 @@ -560,7 +560,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest // Captured from Pywebsocket (r790) - 3 messages with similar parts. - tester.parseIncomingHex( // context takeover (3 messages) + tester.parseIncomingHex(// context takeover (3 messages) "c1 89 88 bc 1b b1 82 75 34 fb 84 bd 79 b1 88", // ToraTora "c1 8b 50 86 88 b2 22 aa 41 9d 1a f2 43 b3 42 86 88", // AtoraFlora "c1 8b e2 3e 05 53 e8 f6 cd 9a cd 74 09 52 80 3e 05" // PhloraTora @@ -578,7 +578,7 @@ public class PerMessageDeflateExtensionTest extends AbstractExtensionTest // Captured from Pywebsocket (r790) - "tora" sent 3 times. - tester.parseIncomingHex( // context takeover (3 messages) + tester.parseIncomingHex(// context takeover (3 messages) "c1 86 69 39 fe 91 43 f0 d1 db 6d 39", // tora 1 "c1 85 2d f3 eb 96 07 f2 89 96 2d", // tora 2 "c1 84 53 ad a5 34 51 cc a5 34" // tora 3 diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadConnection.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadConnection.java index 118b0e5bc1a..c518a2d4c85 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadConnection.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/BlockheadConnection.java @@ -50,7 +50,7 @@ public class BlockheadConnection extends AbstractConnection implements Connectio { private static final int BUFFER_SIZE = 4096; public static final String STATIC_REQUEST_HASH_KEY = "dGhlIHNhbXBsZSBub25jZQ=="; - private final Logger LOG; + private final Logger log; private final WebSocketPolicy policy; private final ByteBufferPool bufferPool; private final Parser parser; @@ -66,7 +66,7 @@ public class BlockheadConnection extends AbstractConnection implements Connectio public BlockheadConnection(WebSocketPolicy policy, ByteBufferPool bufferPool, ExtensionStack extensionStack, CompletableFuture openFut, EndPoint endp, Executor executor) { super(endp, executor); - this.LOG = Log.getLogger(this.getClass()); + this.log = Log.getLogger(this.getClass()); this.policy = policy; this.bufferPool = bufferPool; this.parser = new Parser(policy, bufferPool); @@ -189,7 +189,7 @@ public class BlockheadConnection extends AbstractConnection implements Connectio public void processConnectionError(Throwable cause) { - LOG.warn("Connection Error", cause); + log.warn("Connection Error", cause); if (this.openFuture != null) this.openFuture.completeExceptionally(cause); } @@ -263,9 +263,9 @@ public class BlockheadConnection extends AbstractConnection implements Connectio */ protected void setInitialBuffer(ByteBuffer prefilled) { - if (LOG.isDebugEnabled()) + if (log.isDebugEnabled()) { - LOG.debug("set Initial Buffer - {}", BufferUtil.toDetailString(prefilled)); + log.debug("set Initial Buffer - {}", BufferUtil.toDetailString(prefilled)); } if ((prefilled != null) && (prefilled.hasRemaining())) @@ -294,8 +294,8 @@ public class BlockheadConnection extends AbstractConnection implements Connectio int filled = getEndPoint().fill(nBuffer); - if (LOG.isDebugEnabled()) - LOG.debug("endpointFill() filled={}: {}", filled, BufferUtil.toDetailString(nBuffer)); + if (log.isDebugEnabled()) + log.debug("endpointFill() filled={}: {}", filled, BufferUtil.toDetailString(nBuffer)); if (filled < 0) { diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RawFrameBuilder.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RawFrameBuilder.java index ac1df8e8c51..3aca892b992 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RawFrameBuilder.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/test/RawFrameBuilder.java @@ -36,7 +36,7 @@ public class RawFrameBuilder buf.put(b); } - public static void putLengthAndMask(ByteBuffer buf, int length, byte mask[]) + public static void putLengthAndMask(ByteBuffer buf, int length, byte[] mask) { if (mask != null) { @@ -50,7 +50,7 @@ public class RawFrameBuilder } } - public static byte[] mask(final byte[] data, final byte mask[]) + public static byte[] mask(final byte[] data, final byte[] mask) { assertThat("Mask.length", mask.length, is(4)); int len = data.length; @@ -96,7 +96,7 @@ public class RawFrameBuilder } } - public static void putMask(ByteBuffer buf, byte mask[]) + public static void putMask(ByteBuffer buf, byte[] mask) { assertThat("Mask.length", mask.length, is(4)); buf.put(mask); diff --git a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Hex.java b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Hex.java index 706272e4a82..8ea8ed5991f 100644 --- a/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Hex.java +++ b/jetty-websocket/websocket-common/src/test/java/org/eclipse/jetty/websocket/common/util/Hex.java @@ -64,7 +64,7 @@ public final class Hex return ByteBuffer.wrap(asByteArray(hstr)); } - public static String asHex(byte buf[]) + public static String asHex(byte[] buf) { int len = buf.length; char[] out = new char[len * 2]; diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java index 62b53aa2c68..3c60c4ac3f6 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/WebSocketServletRFCTest.java @@ -109,9 +109,9 @@ public class WebSocketServletRFCTest try (BlockheadConnection clientConn = connFut.get(Timeouts.CONNECT, Timeouts.CONNECT_UNIT)) { // Generate binary frames - byte buf1[] = new byte[128]; - byte buf2[] = new byte[128]; - byte buf3[] = new byte[128]; + byte[] buf1 = new byte[128]; + byte[] buf2 = new byte[128]; + byte[] buf3 = new byte[128]; Arrays.fill(buf1, (byte)0xAA); Arrays.fill(buf2, (byte)0xBB); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java index 493049dab83..9b1f915223e 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/ABSocket.java @@ -41,7 +41,7 @@ public class ABSocket private Session session; @OnWebSocketMessage - public void onBinary(byte buf[], int offset, int len) + public void onBinary(byte[] buf, int offset, int len) { LOG.debug("onBinary(byte[{}],{},{})", buf.length, offset, len); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java index 4f6d2ecd930..0bec817cec2 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6.java @@ -48,7 +48,7 @@ public class TestABCase6 extends AbstractABCase * @param frames the frames * @param msg the message */ - protected void fragmentText(List frames, byte msg[]) + protected void fragmentText(List frames, byte[] msg) { int len = msg.length; boolean continuation = false; @@ -282,9 +282,9 @@ public class TestABCase6 extends AbstractABCase @Test public void testCase6_4_1() throws Exception { - byte part1[] = StringUtil.getUtf8Bytes("\u03BA\u1F79\u03C3\u03BC\u03B5"); - byte part2[] = Hex.asByteArray("F4908080"); // invalid - byte part3[] = StringUtil.getUtf8Bytes("edited"); + byte[] part1 = StringUtil.getUtf8Bytes("\u03BA\u1F79\u03C3\u03BC\u03B5"); + byte[] part2 = Hex.asByteArray("F4908080"); // invalid + byte[] part3 = StringUtil.getUtf8Bytes("edited"); ByteBuffer b1 = ByteBuffer.wrap(part1); ByteBuffer b2 = ByteBuffer.wrap(part2); @@ -322,9 +322,9 @@ public class TestABCase6 extends AbstractABCase @Test public void testCase6_4_2() throws Exception { - byte part1[] = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F4"); // split code point - byte part2[] = Hex.asByteArray("90"); // continue code point & invalid - byte part3[] = Hex.asByteArray("8080656469746564"); // continue code point & finish + byte[] part1 = Hex.asByteArray("CEBAE1BDB9CF83CEBCCEB5F4"); // split code point + byte[] part2 = Hex.asByteArray("90"); // continue code point & invalid + byte[] part3 = Hex.asByteArray("8080656469746564"); // continue code point & finish ByteBuffer b1 = ByteBuffer.wrap(part1); ByteBuffer b2 = ByteBuffer.wrap(part2); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java index 80e28695d98..2a1a32c5882 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/ab/TestABCase6_BadUTF.java @@ -72,13 +72,13 @@ public class TestABCase6_BadUTF extends AbstractABCase data.add(new String[]{"6.12.6", "80BF80BF80"}); data.add(new String[]{"6.12.7", "80BF80BF80BF"}); data.add(new String[]{ - "6.12.8", "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9" - + "FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" + "6.12.8", "808182838485868788898A8B8C8D8E8F909192939495969798999A9B9C9D9E9" + + "FA0A1A2A3A4A5A6A7A8A9AAABACADAEAFB0B1B2B3B4B5B6B7B8B9BABBBCBDBE" }); // - lonely start characters data.add(new String[]{ - "6.13.1", "C020C120C220C320C420C520C620C720C820C920CA20CB20CC20CD20CE20CF2" - + "0D020D120D220D320D420D520D620D720D820D920DA20DB20DC20DD20DE20" + "6.13.1", "C020C120C220C320C420C520C620C720C820C920CA20CB20CC20CD20CE20CF2" + + "0D020D120D220D320D420D520D620D720D820D920DA20DB20DC20DD20DE20" }); data.add(new String[]{"6.13.2", "E020E120E220E320E420E520E620E720E820E920EA20EB20EC20ED20EE20"}); data.add(new String[]{"6.13.3", "F020F120F220F320F420F520F620"}); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/BigEchoSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/BigEchoSocket.java index 3ac826109a9..18f09f9a503 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/BigEchoSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/BigEchoSocket.java @@ -39,7 +39,7 @@ public class BigEchoSocket private static final Logger LOG = Log.getLogger(BigEchoSocket.class); @OnWebSocketMessage - public void onBinary(Session session, byte buf[], int offset, int length) throws IOException + public void onBinary(Session session, byte[] buf, int offset, int length) throws IOException { if (!session.isOpen()) { diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/EchoBroadcastSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/EchoBroadcastSocket.java index cb979e9bfe0..237b1e25ccf 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/EchoBroadcastSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/examples/echo/EchoBroadcastSocket.java @@ -35,7 +35,7 @@ public class EchoBroadcastSocket protected Session session; @OnWebSocketMessage - public void onBinary(byte buf[], int offset, int len) + public void onBinary(byte[] buf, int offset, int len) { ByteBuffer data = ByteBuffer.wrap(buf, offset, len); for (EchoBroadcastSocket sock : BROADCAST) diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java index 0883e652edd..0e07e7a11a0 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/EchoSocket.java @@ -41,7 +41,7 @@ public class EchoSocket private Session session; @OnWebSocketMessage - public void onBinary(byte buf[], int offset, int len) throws IOException + public void onBinary(byte[] buf, int offset, int len) throws IOException { LOG.debug("onBinary(byte[{}],{},{})", buf.length, offset, len); diff --git a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java index 7e9079e97da..1eeda7a69bb 100644 --- a/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java +++ b/jetty-websocket/websocket-server/src/test/java/org/eclipse/jetty/websocket/server/helper/RFCSocket.java @@ -39,7 +39,7 @@ public class RFCSocket private Session session; @OnWebSocketMessage - public void onBinary(byte buf[], int offset, int len) throws IOException + public void onBinary(byte[] buf, int offset, int len) throws IOException { LOG.debug("onBinary(byte[{}],{},{})", buf.length, offset, len); diff --git a/jetty-websocket/websocket-servlet/src/test/java/examples/MyBinaryEchoSocket.java b/jetty-websocket/websocket-servlet/src/test/java/examples/MyBinaryEchoSocket.java index 6f26e450800..81b7b2912ba 100644 --- a/jetty-websocket/websocket-servlet/src/test/java/examples/MyBinaryEchoSocket.java +++ b/jetty-websocket/websocket-servlet/src/test/java/examples/MyBinaryEchoSocket.java @@ -31,7 +31,7 @@ import org.eclipse.jetty.websocket.api.annotations.WebSocket; public class MyBinaryEchoSocket { @OnWebSocketMessage - public void onWebSocketText(Session session, byte buf[], int offset, int len) + public void onWebSocketText(Session session, byte[] buf, int offset, int len) { // Echo message back, asynchronously session.getRemote().sendBytes(ByteBuffer.wrap(buf, offset, len), null); diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/TestConfiguration.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/TestConfiguration.java index 66cac9ef9ba..1be2cd3cb92 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/TestConfiguration.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/TestConfiguration.java @@ -34,7 +34,7 @@ public class TestConfiguration extends HashMap { public static int VALUE = 77; - public final Object ID = new Object(); + public final Object id = new Object(); public final String name; public TestConfiguration nested; diff --git a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java index edccbdaa02f..fa029e17008 100644 --- a/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java +++ b/jetty-xml/src/test/java/org/eclipse/jetty/xml/XmlConfigurationTest.java @@ -54,6 +54,7 @@ import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.Matchers.startsWith; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -102,8 +103,8 @@ public class XmlConfigurationTest assertEquals(2, tc.get("TestInt"), "Put type"); assertEquals("PutValue", tc.get("Trim"), "Trim"); - assertEquals(null, tc.get("Null"), "Null"); - assertEquals(null, tc.get("NullTrim"), "NullTrim"); + assertNull(tc.get("Null"), "Null"); + assertNull(tc.get("NullTrim"), "NullTrim"); assertEquals(1.2345, tc.get("ObjectTrim"), "ObjectTrim"); assertEquals("-1String", tc.get("Objects"), "Objects"); @@ -127,7 +128,7 @@ public class XmlConfigurationTest assertEquals("Blah", tc.oa[0], "oa[0]"); assertEquals("1.2.3.4:5678", tc.oa[1], "oa[1]"); assertEquals(1.2345, tc.oa[2], "oa[2]"); - assertEquals(null, tc.oa[3], "oa[3]"); + assertNull(tc.oa[3], "oa[3]"); assertEquals(1, tc.ia[0], "ia[0]"); assertEquals(2, tc.ia[1], "ia[1]"); @@ -135,10 +136,10 @@ public class XmlConfigurationTest assertEquals(0, tc.ia[3], "ia[3]"); TestConfiguration tc2 = tc.nested; - assertTrue(tc2 != null); + assertNotNull(tc2); assertEquals(true, tc2.get("Arg"), "Called(bool)"); - assertEquals(null, tc.get("Arg"), "nested config"); + assertNull(tc.get("Arg"), "nested config"); assertEquals(true, tc2.get("Arg"), "nested config"); assertEquals("Call1", tc2.testObject, "nested config"); @@ -197,8 +198,8 @@ public class XmlConfigurationTest assertEquals(2, tc.get("TestInt"), "Put type"); assertEquals("PutValue", tc.get("Trim"), "Trim"); - assertEquals(null, tc.get("Null"), "Null"); - assertEquals(null, tc.get("NullTrim"), "NullTrim"); + assertNull(tc.get("Null"), "Null"); + assertNull(tc.get("NullTrim"), "NullTrim"); assertEquals(1.2345, tc.get("ObjectTrim"), "ObjectTrim"); assertEquals("-1String", tc.get("Objects"), "Objects"); @@ -220,7 +221,7 @@ public class XmlConfigurationTest assertEquals("Blah", tc.oa[0], "oa[0]"); assertEquals("1.2.3.4:5678", tc.oa[1], "oa[1]"); assertEquals(1.2345, tc.oa[2], "oa[2]"); - assertEquals(null, tc.oa[3], "oa[3]"); + assertNull(tc.oa[3], "oa[3]"); assertEquals(1, tc.ia[0], "ia[0]"); assertEquals(2, tc.ia[1], "ia[1]"); @@ -228,10 +229,10 @@ public class XmlConfigurationTest assertEquals(0, tc.ia[3], "ia[3]"); TestConfiguration tc2 = tc.nested; - assertTrue(tc2 != null); + assertNotNull(tc2); assertEquals(true, tc2.get("Arg"), "Called(bool)"); - assertEquals(null, tc.get("Arg"), "nested config"); + assertNull(tc.get("Arg"), "nested config"); assertEquals(true, tc2.get("Arg"), "nested config"); assertEquals("Call1", tc2.testObject, "nested config"); @@ -296,9 +297,9 @@ public class XmlConfigurationTest @Test public void testListConstructorArg() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + "" - + STRING_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + "" + + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet", tc.getList(), is(nullValue())); xmlConfiguration.configure(tc); @@ -309,11 +310,11 @@ public class XmlConfigurationTest @Test public void testTwoArgumentListConstructorArg() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + "" - + "" + STRING_ARRAY_XML + "" - + "" + STRING_ARRAY_XML + "" - + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + "" + + "" + STRING_ARRAY_XML + "" + + "" + STRING_ARRAY_XML + "" + + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet", tc.getList(), is(nullValue())); xmlConfiguration.configure(tc); @@ -324,8 +325,8 @@ public class XmlConfigurationTest @Test public void testListNotContainingArray() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + "Some String"); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + "Some String"); TestConfiguration tc = new TestConfiguration(); assertThrows(IllegalArgumentException.class, () -> @@ -337,9 +338,9 @@ public class XmlConfigurationTest @Test public void testSetConstructorArg() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + "" - + STRING_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + "" + + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet", tc.getSet(), is(nullValue())); xmlConfiguration.configure(tc); @@ -350,8 +351,8 @@ public class XmlConfigurationTest @Test public void testSetNotContainingArray() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + "Some String"); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + "Some String"); TestConfiguration tc = new TestConfiguration(); assertThrows(IllegalArgumentException.class, () -> { @@ -362,8 +363,8 @@ public class XmlConfigurationTest @Test public void testListSetterWithStringArray() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + STRING_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet", tc.getList(), is(nullValue())); xmlConfiguration.configure(tc); @@ -373,8 +374,8 @@ public class XmlConfigurationTest @Test public void testListSetterWithPrimitiveArray() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + INT_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getList() returns null as it's not configured yet", tc.getList(), is(nullValue())); xmlConfiguration.configure(tc); @@ -384,8 +385,8 @@ public class XmlConfigurationTest @Test public void testNotSupportedLinkedListSetter() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + INT_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue())); assertThrows(NoSuchMethodException.class, () -> @@ -397,8 +398,8 @@ public class XmlConfigurationTest @Test public void testArrayListSetter() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + INT_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getList(), is(nullValue())); xmlConfiguration.configure(tc); @@ -408,8 +409,8 @@ public class XmlConfigurationTest @Test public void testSetSetter() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + STRING_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + STRING_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue())); xmlConfiguration.configure(tc); @@ -419,8 +420,8 @@ public class XmlConfigurationTest @Test public void testSetSetterWithPrimitiveArray() throws Exception { - XmlConfiguration xmlConfiguration = asXmlConfiguration("" - + INT_ARRAY_XML + ""); + XmlConfiguration xmlConfiguration = asXmlConfiguration("" + + INT_ARRAY_XML + ""); TestConfiguration tc = new TestConfiguration(); assertThat("tc.getSet() returns null as it's not configured yet", tc.getSet(), is(nullValue())); xmlConfiguration.configure(tc); @@ -1002,7 +1003,7 @@ public class XmlConfigurationTest } @Test - public void testJettyStandardIdsAndProperties_JettyHome_JettyBase() throws Exception + public void testJettyStandardIdsAndPropertiesAndJettyHomeAndJettyBase() throws Exception { String[] propNames = new String[] { @@ -1031,7 +1032,7 @@ public class XmlConfigurationTest } @Test - public void testJettyStandardIdsAndProperties_JettyHomeUri_JettyBaseUri() throws Exception + public void testJettyStandardIdsAndPropertiesAndJettyHomeUriAndJettyBaseUri() throws Exception { String[] propNames = new String[] { @@ -1085,7 +1086,7 @@ public class XmlConfigurationTest if (logBytes != null) { - String[] lines = logBytes.toString("UTF-8").split(System.lineSeparator()); + String[] lines = logBytes.toString(UTF_8.name()).split(System.lineSeparator()); List warnings = Arrays.stream(lines) .filter(line -> line.contains(":WARN:")) .filter(line -> line.contains(testClass.getSimpleName())) diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java index 79570423ea6..43b20548444 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/CDITests.java @@ -50,7 +50,7 @@ public class CDITests extends AbstractDistributionTest Path jettyWebXml = d.getJettyBase().resolve("webapps/demo/WEB-INF/jetty-web.xml"); Files.move(jettyWebOwbXml, jettyWebXml); } - catch(IOException e) + catch (IOException e) { throw new RuntimeException(e); } @@ -88,7 +88,7 @@ public class CDITests extends AbstractDistributionTest String[] args1 = { "--create-startd", "--approve-all-licenses", - "--add-to-start=http,deploy,annotations,jsp" + (integration==null?"":(","+integration)) + "--add-to-start=http,deploy,annotations,jsp" + (integration == null ? "" : ("," + integration)) }; try (DistributionTester.Run run1 = distribution.start(args1)) { diff --git a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DynamicListenerTests.java b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DynamicListenerTests.java index 86d0b2d10b0..c80ca9c0941 100644 --- a/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DynamicListenerTests.java +++ b/tests/test-distribution/src/test/java/org/eclipse/jetty/tests/distribution/DynamicListenerTests.java @@ -18,19 +18,20 @@ package org.eclipse.jetty.tests.distribution; -import org.eclipse.jetty.client.api.ContentResponse; -import org.eclipse.jetty.http.HttpStatus; -import org.eclipse.jetty.util.IO; -import org.junit.jupiter.api.Test; - import java.io.File; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.concurrent.TimeUnit; +import org.eclipse.jetty.client.api.ContentResponse; +import org.eclipse.jetty.http.HttpStatus; +import org.eclipse.jetty.util.IO; +import org.junit.jupiter.api.Test; + import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.not; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -40,7 +41,7 @@ public class DynamicListenerTests @Test public void testSimpleWebAppWithJSP() throws Exception { - Path jettyBase = Files.createTempDirectory( "jetty_base"); + Path jettyBase = Files.createTempDirectory("jetty_base"); String jettyVersion = System.getProperty("jettyVersion"); DistributionTester distribution = DistributionTester.Builder.newInstance() .jettyBase(jettyBase) @@ -58,11 +59,11 @@ public class DynamicListenerTests assertTrue(run1.awaitFor(5, TimeUnit.SECONDS)); assertEquals(0, run1.getExitValue()); - File war = distribution.resolveArtifact( "org.eclipse.jetty:test-jetty-webapp:war:" + jettyVersion); + File war = distribution.resolveArtifact("org.eclipse.jetty:test-jetty-webapp:war:" + jettyVersion); distribution.installWarFile(war, "test"); Path etc = Paths.get(jettyBase.toString(),"etc"); - if(!Files.exists(etc)) + if (!Files.exists(etc)) { Files.createDirectory(etc); } @@ -89,7 +90,8 @@ public class DynamicListenerTests assertThat(content, containsString("requestInitialized")); assertThat(content, not(containsString("<%"))); } - } finally + } + finally { IO.delete(jettyBase.toFile()); } diff --git a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java index c868796d1ad..34fb4fe4bc8 100644 --- a/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java +++ b/tests/test-http-client-transport/src/test/java/org/eclipse/jetty/http/client/AsyncIOServletTest.java @@ -311,9 +311,11 @@ public class AsyncIOServletTest extends AbstractTest cache = __testSupport.getCache(); + Cache cache = _testSupport.getCache(); SessionData sd1 = new SessionData("sd1", "", "", 0, 0, 0, 0); SessionData sd2 = new SessionData("sd2", "", "", 0, 0, 0, 1000); diff --git a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/TestContextScopeListener.java b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/TestContextScopeListener.java index 34a3351860c..99f4d0e13a2 100644 --- a/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/TestContextScopeListener.java +++ b/tests/test-sessions/test-sessions-common/src/main/java/org/eclipse/jetty/server/session/TestContextScopeListener.java @@ -59,7 +59,7 @@ public class TestContextScopeListener implements ContextScopeListener { if (request != null && !listenerAdded) { - listenerAdded=true; + listenerAdded = true; request.getHttpChannel().addListener(new Listener() { @Override diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java index 7f4dcee3d7c..4a0f031b2f6 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/AsyncTest.java @@ -102,6 +102,7 @@ public class AsyncTest server.stop(); } } + @Test public void testSessionWithAsyncComplete() throws Exception { @@ -262,10 +263,7 @@ public class AsyncTest server.stop(); } } - - - - + @Test public void testSessionWithCrossContextAsyncComplete() throws Exception { diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DefaultSessionCacheTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DefaultSessionCacheTest.java index 4b381f772ab..87182acca2f 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DefaultSessionCacheTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/DefaultSessionCacheTest.java @@ -18,16 +18,6 @@ package org.eclipse.jetty.server.session; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.containsInAnyOrder; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; -import static org.junit.jupiter.api.Assertions.assertSame; -import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.junit.jupiter.api.Assertions.fail; - import java.util.Collections; import java.util.Random; import java.util.Set; @@ -42,6 +32,16 @@ import org.eclipse.jetty.server.Server; import org.eclipse.jetty.servlet.ServletContextHandler; import org.junit.jupiter.api.Test; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertSame; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; + /** * DefaultSessionCacheTest */ @@ -65,8 +65,7 @@ public class DefaultSessionCacheTest ++activateCalls; } } - - + @Test public void testRenewWithInvalidate() throws Exception { @@ -162,25 +161,20 @@ public class DefaultSessionCacheTest } ); - Thread invalidateThread = new Thread(new Runnable() + Thread invalidateThread = new Thread(() -> { - - @Override - public void run() + //simulate req4 doing an invalidate that we hope overlaps with req3 renewId + try { - //simulate req4 doing an invalidate that we hope overlaps with req3 renewId - try - { - Random random = new Random(); - if ((random.nextInt(10) % 2) == 0) - Thread.currentThread().sleep(2); //small sleep to try and make timing more random - ((Session)s4).invalidate(); - assertFalse(((Session)s4).isValid()); - } - catch (InterruptedException e) - { - - } + Random random = new Random(); + if ((random.nextInt(10) % 2) == 0) + Thread.currentThread().sleep(2); //small sleep to try and make timing more random + ((Session)s4).invalidate(); + assertFalse(((Session)s4).isValid()); + } + catch (InterruptedException e) + { + // no op } } ); @@ -559,7 +553,7 @@ public class DefaultSessionCacheTest assertFalse(cache.contains("1234")); //test remove of session in both store and cache - session = cache.newSession(null, "1234",now - 20 ,TimeUnit.MINUTES.toMillis(10));//saveOnCreate ensures write to store + session = cache.newSession(null, "1234",now - 20, TimeUnit.MINUTES.toMillis(10));//saveOnCreate ensures write to store cache.add("1234", session); assertTrue(store.exists("1234")); assertTrue(cache.contains("1234")); diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionListenerTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionListenerTest.java index de387916ef0..873ea3e3569 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionListenerTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionListenerTest.java @@ -184,7 +184,7 @@ public class SessionListenerTest assertThat(sessionId, is(in(listener.createdSessions))); //and wait until the session should have expired - Thread.currentThread().sleep(TimeUnit.SECONDS.toMillis(inactivePeriod + (2*scavengePeriod))); + Thread.currentThread().sleep(TimeUnit.SECONDS.toMillis(inactivePeriod + (2 * scavengePeriod))); assertThat(sessionId, is(in(listener.destroyedSessions))); diff --git a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java index 2329b49f0a1..828991aee94 100644 --- a/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java +++ b/tests/test-sessions/test-sessions-common/src/test/java/org/eclipse/jetty/server/session/SessionRenewTest.java @@ -173,6 +173,7 @@ public class SessionRenewTest _server.stop(); } } + /** * Perform the test by making a request to create a session * then another request that will renew the session id. @@ -280,6 +281,7 @@ public class SessionRenewTest } } + public static class TestServlet extends HttpServlet { private static final long serialVersionUID = 1L; diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/DispatchServletTest.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/DispatchServletTest.java index 2e627933b64..9b33bd10569 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/DispatchServletTest.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/DispatchServletTest.java @@ -101,7 +101,7 @@ public class DispatchServletTest tester.addServlet(DefaultServlet.class, "/"); tester.start(); - String selfRefs[] = + String[] selfRefs = {"/dispatch/forward", "/dispatch/includeS", "/dispatch/includeW", "/dispatch/includeN",}; /*