diff --git a/src/main/java/hudson/remoting/AbstractByteArrayCommandTransport.java b/src/main/java/hudson/remoting/AbstractByteArrayCommandTransport.java index 7b2a69d2b..ac0c8eb9a 100644 --- a/src/main/java/hudson/remoting/AbstractByteArrayCommandTransport.java +++ b/src/main/java/hudson/remoting/AbstractByteArrayCommandTransport.java @@ -1,12 +1,13 @@ package hudson.remoting; +import org.jenkinsci.remoting.util.AnonymousClassWarnings; + +import javax.annotation.Nonnull; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; import java.util.logging.Level; import java.util.logging.Logger; -import javax.annotation.Nonnull; -import org.jenkinsci.remoting.util.AnonymousClassWarnings; /** * {@link CommandTransport} that works with {@code byte[]} instead of command object. @@ -38,7 +39,7 @@ public abstract class AbstractByteArrayCommandTransport extends CommandTransport */ public abstract void setup(@Nonnull ByteArrayReceiver receiver); - public static interface ByteArrayReceiver { + public interface ByteArrayReceiver { /** * Notifies the {@link Channel} that the transport has received a new block. * diff --git a/src/main/java/hudson/remoting/BinarySafeStream.java b/src/main/java/hudson/remoting/BinarySafeStream.java index c777e91bd..a682ab24c 100644 --- a/src/main/java/hudson/remoting/BinarySafeStream.java +++ b/src/main/java/hudson/remoting/BinarySafeStream.java @@ -23,13 +23,13 @@ */ package hudson.remoting; +import java.io.ByteArrayOutputStream; import java.io.FilterInputStream; +import java.io.FilterOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.io.FilterOutputStream; -import java.io.UnsupportedEncodingException; -import java.io.ByteArrayOutputStream; +import java.nio.charset.StandardCharsets; import java.util.Arrays; /** @@ -315,11 +315,7 @@ public void flush() throws IOException { private static final int[] DECODING_TABLE = new int[128]; static { - try { - ENCODING_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new AssertionError(e); - } + ENCODING_TABLE = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/".getBytes(StandardCharsets.US_ASCII); Arrays.fill(DECODING_TABLE,-2); for (int i = 0; i < ENCODING_TABLE.length; i++) diff --git a/src/main/java/hudson/remoting/Channel.java b/src/main/java/hudson/remoting/Channel.java index d53ca96bf..ec3b41a87 100644 --- a/src/main/java/hudson/remoting/Channel.java +++ b/src/main/java/hudson/remoting/Channel.java @@ -33,9 +33,13 @@ import org.jenkinsci.remoting.CallableDecorator; import org.jenkinsci.remoting.RoleChecker; import org.jenkinsci.remoting.nio.NioChannelHub; +import org.jenkinsci.remoting.util.LoggingChannelListener; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.Closeable; import java.io.File; import java.io.IOException; @@ -43,9 +47,9 @@ import java.io.ObjectOutputStream; import java.io.OutputStream; import java.io.PrintWriter; -import java.io.UnsupportedEncodingException; import java.lang.ref.WeakReference; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.Collections; import java.util.Date; import java.util.Hashtable; @@ -63,10 +67,6 @@ import java.util.logging.Level; import java.util.logging.LogRecord; import java.util.logging.Logger; -import javax.annotation.Nullable; -import org.jenkinsci.remoting.util.LoggingChannelListener; -import org.kohsuke.accmod.Restricted; -import org.kohsuke.accmod.restrictions.NoExternalUse; /** * Represents a communication channel to the remote peer. @@ -389,11 +389,7 @@ public enum Mode { /*package*/ final byte[] preamble; Mode(String preamble) { - try { - this.preamble = preamble.getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new Error(e); - } + this.preamble = preamble.getBytes(StandardCharsets.US_ASCII); } Mode(byte[] preamble) { diff --git a/src/main/java/hudson/remoting/CommandTransport.java b/src/main/java/hudson/remoting/CommandTransport.java index 9a440cae9..19aecfd34 100644 --- a/src/main/java/hudson/remoting/CommandTransport.java +++ b/src/main/java/hudson/remoting/CommandTransport.java @@ -1,10 +1,10 @@ package hudson.remoting; +import javax.annotation.CheckForNull; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.OutputStream; -import javax.annotation.CheckForNull; /** * Lower level abstraction under {@link Channel} for sending and receiving commands @@ -58,7 +58,7 @@ protected CommandTransport() { * SPI implemented by {@link Channel} so that the transport can pass the received command * to {@link Channel} for processing. */ - protected static interface CommandReceiver { + protected interface CommandReceiver { /** * Notifies the channel that a new {@link Command} was received from the other side. * diff --git a/src/main/java/hudson/remoting/FastPipedOutputStream.java b/src/main/java/hudson/remoting/FastPipedOutputStream.java index 05a390501..5f79711e6 100644 --- a/src/main/java/hudson/remoting/FastPipedOutputStream.java +++ b/src/main/java/hudson/remoting/FastPipedOutputStream.java @@ -20,9 +20,9 @@ */ package hudson.remoting; +import java.io.IOException; import java.io.InterruptedIOException; import java.io.OutputStream; -import java.io.IOException; import java.lang.ref.WeakReference; /** @@ -78,7 +78,7 @@ public FastPipedOutputStream(FastPipedInputStream sink, int bufferSize) throws I private FastPipedInputStream sink() throws IOException { FastPipedInputStream s = sink.get(); - if (s==null) throw (IOException)new IOException("Reader side has already been abandoned").initCause(allocatedAt); + if (s==null) throw new IOException("Reader side has already been abandoned", allocatedAt); return s; } @@ -151,7 +151,7 @@ public void write(byte[] b, int off, int len) throws IOException { FastPipedInputStream s = sink(); // make sure the sink is still trying to read, or else fail the write. if(s.closed!=null) { - throw (IOException)new IOException("Pipe is already closed").initCause(s.closed); + throw new IOException("Pipe is already closed", s.closed); } synchronized(s.buffer) { diff --git a/src/main/java/hudson/remoting/FileSystemJarCache.java b/src/main/java/hudson/remoting/FileSystemJarCache.java index e3b872b5f..d11cdc1f9 100644 --- a/src/main/java/hudson/remoting/FileSystemJarCache.java +++ b/src/main/java/hudson/remoting/FileSystemJarCache.java @@ -66,7 +66,7 @@ public FileSystemJarCache(@Nonnull File rootDir, boolean touch) { @Override public String toString() { - return String.format("FileSystem JAR Cache: path=%s, touch=%s", rootDir, Boolean.toString(touch)); + return String.format("FileSystem JAR Cache: path=%s, touch=%s", rootDir, touch); } @Override @@ -149,7 +149,7 @@ protected URL retrieve(Channel channel, long sum1, long sum2) throws IOException Files.deleteIfExists(PathUtils.fileToPath(tmp)); } } catch (IOException e) { - throw (IOException)new IOException("Failed to write to "+target).initCause(e); + throw new IOException("Failed to write to "+target, e); } } diff --git a/src/main/java/hudson/remoting/Launcher.java b/src/main/java/hudson/remoting/Launcher.java index 3a7e54d3f..9a32b720a 100644 --- a/src/main/java/hudson/remoting/Launcher.java +++ b/src/main/java/hudson/remoting/Launcher.java @@ -25,78 +25,76 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.remoting.Channel.Mode; - -import java.io.Console; -import java.io.FileInputStream; -import java.io.UnsupportedEncodingException; -import java.nio.file.Path; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchProviderException; -import java.security.PrivilegedActionException; -import java.security.cert.CertificateFactory; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManagerFactory; - import org.jenkinsci.remoting.engine.WorkDirManager; import org.jenkinsci.remoting.util.IOUtils; +import org.jenkinsci.remoting.util.PathUtils; import org.jenkinsci.remoting.util.https.NoCheckHostnameVerifier; import org.jenkinsci.remoting.util.https.NoCheckTrustManager; -import org.jenkinsci.remoting.util.PathUtils; +import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.Option; import org.w3c.dom.Document; import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import org.kohsuke.args4j.Option; -import org.kohsuke.args4j.CmdLineParser; -import org.kohsuke.args4j.CmdLineException; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.crypto.Cipher; import javax.crypto.spec.IvParameterSpec; +import javax.crypto.spec.SecretKeySpec; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.TrustManagerFactory; import javax.xml.XMLConstants; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.TrustManager; -import javax.net.ssl.SSLContext; -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.io.File; import java.io.BufferedInputStream; import java.io.BufferedOutputStream; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.Closeable; +import java.io.Console; +import java.io.File; +import java.io.FileInputStream; import java.io.FileWriter; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.lang.reflect.Method; -import java.net.URL; -import java.net.URLConnection; +import java.net.Authenticator; +import java.net.HttpURLConnection; +import java.net.InetSocketAddress; +import java.net.PasswordAuthentication; import java.net.ServerSocket; import java.net.Socket; +import java.net.URL; import java.net.URLClassLoader; -import java.net.InetSocketAddress; -import java.net.HttpURLConnection; -import java.net.Authenticator; -import java.net.PasswordAuthentication; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; +import java.nio.file.Path; import java.security.GeneralSecurityException; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.PrivilegedActionException; +import java.security.SecureRandom; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; import java.util.ArrayList; +import java.util.Base64; import java.util.List; import java.util.Locale; +import java.util.Properties; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; -import java.security.cert.CertificateException; -import java.security.NoSuchAlgorithmException; -import java.security.KeyManagementException; -import java.security.SecureRandom; -import java.util.Base64; -import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; -import javax.crypto.Cipher; -import javax.crypto.spec.SecretKeySpec; /** * Entry point for running a {@link Channel}. This is the main method of the agent JVM. @@ -461,11 +459,7 @@ private SSLSocketFactory getSSLSocketFactory() continue; } } else { - try { - cert = certOrAtFilename.getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("US-ASCII support is mandated by the JLS", e); - } + cert = certOrAtFilename.getBytes(StandardCharsets.US_ASCII); } try { keyStore.setCertificateEntry(String.format("alias-%d", i++), @@ -508,11 +502,11 @@ public List parseJnlpArguments() throws ParserConfigurationException, SA HttpURLConnection http = (HttpURLConnection) con; if (slaveJnlpCredentials != null) { String userPassword = slaveJnlpCredentials; - String encoding = Base64.getEncoder().encodeToString(userPassword.getBytes("UTF-8")); + String encoding = Base64.getEncoder().encodeToString(userPassword.getBytes(StandardCharsets.UTF_8)); http.setRequestProperty("Authorization", "Basic " + encoding); } if (System.getProperty("proxyCredentials", proxyCredentials) != null) { - String encoding = Base64.getEncoder().encodeToString(System.getProperty("proxyCredentials", proxyCredentials).getBytes("UTF-8")); + String encoding = Base64.getEncoder().encodeToString(System.getProperty("proxyCredentials", proxyCredentials).getBytes(StandardCharsets.UTF_8)); http.setRequestProperty("Proxy-Authorization", "Basic " + encoding); } } @@ -543,7 +537,7 @@ public List parseJnlpArguments() throws ParserConfigurationException, SA byte[] decrypted = cipher.doFinal(payload,16,payload.length-16); input = new ByteArrayInputStream(decrypted); } catch (GeneralSecurityException x) { - throw (IOException)new IOException("Failed to decrypt the JNLP file. Invalid secret key?").initCause(x); + throw new IOException("Failed to decrypt the JNLP file. Invalid secret key?", x); } } if(contentType==null || !contentType.startsWith(expectedContentType)) { @@ -574,14 +568,13 @@ public List parseJnlpArguments() throws ParserConfigurationException, SA } catch (SSLHandshakeException e) { if(e.getMessage().contains("PKIX path building failed")) { // invalid SSL certificate. One reason this happens is when the certificate is self-signed - IOException x = new IOException("Failed to validate a server certificate. If you are using a self-signed certificate, you can use the -noCertificateCheck option to bypass this check."); - x.initCause(e); + IOException x = new IOException("Failed to validate a server certificate. If you are using a self-signed certificate, you can use the -noCertificateCheck option to bypass this check.", e); throw x; } else throw e; } catch (IOException e) { if (this.noReconnect) - throw (IOException)new IOException("Failing to obtain "+slaveJnlpURL).initCause(e); + throw new IOException("Failing to obtain " + slaveJnlpURL, e); System.err.println("Failing to obtain "+slaveJnlpURL); e.printStackTrace(System.err); diff --git a/src/main/java/hudson/remoting/RemoteClassLoader.java b/src/main/java/hudson/remoting/RemoteClassLoader.java index 2e3d0709d..5991b8d16 100644 --- a/src/main/java/hudson/remoting/RemoteClassLoader.java +++ b/src/main/java/hudson/remoting/RemoteClassLoader.java @@ -24,35 +24,37 @@ package hudson.remoting; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.jenkinsci.constant_pool_scanner.ConstantPoolScanner; +import org.jenkinsci.remoting.SerializableOnlyOverRemoting; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.ObjectStreamException; import java.io.Serializable; -import java.net.URL; import java.net.MalformedURLException; +import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; +import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; -import java.util.Map; -import java.util.Vector; +import java.util.HashSet; import java.util.List; -import java.util.ArrayList; -import java.util.Collections; +import java.util.Map; import java.util.Set; -import java.util.HashSet; +import java.util.Vector; import java.util.concurrent.ExecutionException; import java.util.logging.Level; import java.util.logging.Logger; -import org.jenkinsci.constant_pool_scanner.ConstantPoolScanner; -import org.jenkinsci.remoting.SerializableOnlyOverRemoting; - -import javax.annotation.CheckForNull; - -import static hudson.remoting.Util.*; -import static java.util.logging.Level.*; -import javax.annotation.Nonnull; +import static hudson.remoting.Util.getBaseName; +import static hudson.remoting.Util.makeResource; +import static hudson.remoting.Util.readFully; +import static java.util.logging.Level.FINE; +import static java.util.logging.Level.WARNING; /** * Loads class files from the other peer through {@link Channel}. @@ -489,9 +491,9 @@ public Enumeration findResources(String name) throws IOException { // .get() shouldn't block v.add(image.image.resolveURL(channel,name).get()); } catch (InterruptedException e) { - throw (Error)new Error("Failed to load resources "+name).initCause(e); + throw new Error("Failed to load resources "+name, e); } catch (ExecutionException e) { - throw (Error)new Error("Failed to load resources "+name).initCause(e); + throw new Error("Failed to load resources "+name, e); } resourcesMap.put(name,v); @@ -675,7 +677,7 @@ public static class ClassFile2 extends ResourceFile { /** * Remoting interface. */ - public static interface IClassLoader { + public interface IClassLoader { byte[] fetchJar(URL url) throws IOException; /** @@ -1039,7 +1041,7 @@ public String toString() { * any new classpath. In this way, we can effectively use this classloader as a representation * of the bootstrap classloader. */ - private static final ClassLoader PSEUDO_BOOTSTRAP = new URLClassLoader(new URL[0],(ClassLoader)null) { + private static final ClassLoader PSEUDO_BOOTSTRAP = new URLClassLoader(new URL[0], null) { @Override public String toString() { return "PSEUDO_BOOTSTRAP"; diff --git a/src/main/java/hudson/remoting/RemoteInvocationHandler.java b/src/main/java/hudson/remoting/RemoteInvocationHandler.java index b63cb02bd..7a81cc154 100644 --- a/src/main/java/hudson/remoting/RemoteInvocationHandler.java +++ b/src/main/java/hudson/remoting/RemoteInvocationHandler.java @@ -25,6 +25,11 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.remoting.Channel.Ref; +import org.jenkinsci.remoting.RoleChecker; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; @@ -50,10 +55,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.logging.Level; import java.util.logging.Logger; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.jenkinsci.remoting.RoleChecker; /** * Sits behind a proxy object and implements the proxy logic. @@ -181,7 +182,7 @@ static T wrap(Channel channel, int id, Class type, boolean userProxy, boo } /*package*/ static Class getProxyClass(Class type) { - return Proxy.getProxyClass(type.getClassLoader(), new Class[]{type,IReadResolve.class}); + return Proxy.getProxyClass(type.getClassLoader(), type, IReadResolve.class); } /** diff --git a/src/main/java/hudson/remoting/UserRequest.java b/src/main/java/hudson/remoting/UserRequest.java index e86d277f9..67384749d 100644 --- a/src/main/java/hudson/remoting/UserRequest.java +++ b/src/main/java/hudson/remoting/UserRequest.java @@ -24,22 +24,22 @@ package hudson.remoting; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; -import hudson.remoting.RemoteClassLoader.IClassLoader; import hudson.remoting.ExportTable.ExportList; +import hudson.remoting.RemoteClassLoader.IClassLoader; import hudson.remoting.RemoteInvocationHandler.RPCRequest; +import org.jenkinsci.remoting.util.AnonymousClassWarnings; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.Serializable; import java.io.NotSerializableException; import java.io.ObjectInputStream; +import java.io.ObjectOutputStream; +import java.io.Serializable; import java.util.logging.Level; import java.util.logging.Logger; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import org.jenkinsci.remoting.util.AnonymousClassWarnings; /** * {@link Request} that can take {@link Callable} whose actual implementation @@ -271,8 +271,7 @@ private byte[] serialize(Object o, Channel localChannel) throws IOException { try { return _serialize(o,localChannel); } catch( NotSerializableException e ) { - IOException x = new IOException("Unable to serialize " + o); - x.initCause(e); + IOException x = new IOException("Unable to serialize " + o, e); throw x; } } diff --git a/src/main/java/hudson/remoting/Util.java b/src/main/java/hudson/remoting/Util.java index 2d9a45e49..43532dc4c 100644 --- a/src/main/java/hudson/remoting/Util.java +++ b/src/main/java/hudson/remoting/Util.java @@ -5,6 +5,9 @@ import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; +import javax.annotation.Nonnull; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLSocketFactory; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -12,14 +15,12 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.InetSocketAddress; -import java.net.URLConnection; import java.net.MalformedURLException; import java.net.Proxy; import java.net.SocketAddress; import java.net.URL; -import javax.annotation.Nonnull; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.Base64; @@ -127,11 +128,11 @@ static URLConnection openURLConnection(URL url, String credentials, String proxy con = url.openConnection(); } if (credentials != null) { - String encoding = Base64.getEncoder().encodeToString(credentials.getBytes("UTF-8")); + String encoding = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8)); con.setRequestProperty("Authorization", "Basic " + encoding); } if (proxyCredentials != null) { - String encoding = Base64.getEncoder().encodeToString(proxyCredentials.getBytes("UTF-8")); + String encoding = Base64.getEncoder().encodeToString(proxyCredentials.getBytes(StandardCharsets.UTF_8)); con.setRequestProperty("Proxy-Authorization", "Basic " + encoding); } if (con instanceof HttpsURLConnection && sslSocketFactory != null) { diff --git a/src/main/java/hudson/remoting/VirtualChannel.java b/src/main/java/hudson/remoting/VirtualChannel.java index 7ba1a60ba..c7944a70a 100644 --- a/src/main/java/hudson/remoting/VirtualChannel.java +++ b/src/main/java/hudson/remoting/VirtualChannel.java @@ -23,10 +23,10 @@ */ package hudson.remoting; -import java.io.IOException; import javax.annotation.CheckForNull; import javax.annotation.Nonnull; import javax.annotation.Nullable; +import java.io.IOException; /** * Virtualized {@link Channel} that allows different implementations. @@ -88,7 +88,7 @@ public interface VirtualChannel { * If the current thread is interrupted while waiting for the completion. * @since 1.300 */ - public void join() throws InterruptedException; + void join() throws InterruptedException; /** * Waits for this {@link Channel} to be closed down, but only up the given milliseconds. @@ -97,7 +97,7 @@ public interface VirtualChannel { * If the current thread is interrupted while waiting for the completion. * @since 1.300 */ - public void join(long timeout) throws InterruptedException; + void join(long timeout) throws InterruptedException; /** * Exports an object for remoting to the other {@link Channel} diff --git a/src/main/java/hudson/remoting/Which.java b/src/main/java/hudson/remoting/Which.java index abafbbee7..a23f26c70 100644 --- a/src/main/java/hudson/remoting/Which.java +++ b/src/main/java/hudson/remoting/Which.java @@ -29,18 +29,18 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.io.InputStream; -import java.net.URL; -import java.net.MalformedURLException; -import java.net.URLConnection; -import java.net.JarURLConnection; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; -import java.util.zip.ZipFile; +import java.net.JarURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.util.jar.JarFile; -import java.util.logging.Logger; import java.util.logging.Level; +import java.util.logging.Logger; +import java.util.zip.ZipFile; /** * Locates where a given class is loaded from. @@ -248,11 +248,7 @@ private static String decode(String s) { } baos.write(ch); } - try { - return new String(baos.toByteArray(),"UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new Error(e); // impossible - } + return new String(baos.toByteArray(), StandardCharsets.UTF_8); } private static int hexToInt(int ch) { diff --git a/src/main/java/hudson/remoting/jnlp/Main.java b/src/main/java/hudson/remoting/jnlp/Main.java index 3f4e25701..4272d0e62 100644 --- a/src/main/java/hudson/remoting/jnlp/Main.java +++ b/src/main/java/hudson/remoting/jnlp/Main.java @@ -24,40 +24,37 @@ package hudson.remoting.jnlp; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import hudson.remoting.Engine; +import hudson.remoting.EngineListener; import hudson.remoting.FileSystemJarCache; -import java.io.ByteArrayInputStream; -import java.io.FileInputStream; -import java.io.UnsupportedEncodingException; -import java.security.cert.CertificateException; -import java.security.cert.CertificateFactory; -import java.security.cert.X509Certificate; - import hudson.remoting.Util; import org.jenkinsci.remoting.engine.WorkDirManager; import org.jenkinsci.remoting.util.PathUtils; -import org.kohsuke.args4j.Option; -import org.kohsuke.args4j.CmdLineParser; import org.kohsuke.args4j.Argument; import org.kohsuke.args4j.CmdLineException; +import org.kohsuke.args4j.CmdLineParser; +import org.kohsuke.args4j.Option; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import java.io.ByteArrayInputStream; import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.net.URL; +import java.nio.charset.StandardCharsets; +import java.security.cert.CertificateException; +import java.security.cert.CertificateFactory; +import java.security.cert.X509Certificate; +import java.util.ArrayList; import java.util.HashSet; -import java.util.logging.Logger; +import java.util.List; import java.util.logging.Level; +import java.util.logging.Logger; + import static java.util.logging.Level.INFO; import static java.util.logging.Level.WARNING; -import java.util.List; -import java.util.ArrayList; -import java.net.URL; -import java.io.IOException; - -import hudson.remoting.Engine; -import hudson.remoting.EngineListener; - -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; - /** * Entry point to JNLP agent. * @@ -374,12 +371,7 @@ public Engine createEngine() { continue; } } else { - try { - cert = certOrAtFilename.getBytes("US-ASCII"); - } catch (UnsupportedEncodingException e) { - LOGGER.log(Level.WARNING, "Could not parse certificate " + certOrAtFilename, e); - continue; - } + cert = certOrAtFilename.getBytes(StandardCharsets.US_ASCII); } try { certificates.add((X509Certificate) factory.generateCertificate(new ByteArrayInputStream(cert))); diff --git a/src/main/java/org/jenkinsci/remoting/engine/EngineUtil.java b/src/main/java/org/jenkinsci/remoting/engine/EngineUtil.java index d805f3bf7..ecb600af4 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/EngineUtil.java +++ b/src/main/java/org/jenkinsci/remoting/engine/EngineUtil.java @@ -26,12 +26,13 @@ import org.kohsuke.accmod.Restricted; import org.kohsuke.accmod.restrictions.NoExternalUse; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; import java.io.InputStream; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; +import java.nio.charset.StandardCharsets; import java.util.Properties; import java.util.logging.Level; import java.util.logging.Logger; @@ -81,7 +82,7 @@ public static String readChars(InputStream inputStream, int len) throws IOExcept buf[i] = (byte)inputStream.read(); } - return new String(buf,"UTF-8"); + return new String(buf, StandardCharsets.UTF_8); } /** diff --git a/src/main/java/org/jenkinsci/remoting/engine/HandshakeCiphers.java b/src/main/java/org/jenkinsci/remoting/engine/HandshakeCiphers.java index 9c8d14db4..e342f0be3 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/HandshakeCiphers.java +++ b/src/main/java/org/jenkinsci/remoting/engine/HandshakeCiphers.java @@ -23,6 +23,9 @@ */ package org.jenkinsci.remoting.engine; +import org.kohsuke.accmod.Restricted; +import org.kohsuke.accmod.restrictions.NoExternalUse; + import javax.crypto.Cipher; import javax.crypto.SecretKey; import javax.crypto.SecretKeyFactory; @@ -121,7 +124,7 @@ public static HandshakeCiphers create(String salt, String secret) { return new HandshakeCiphers(secretKey, spec, encryptCipher, decryptCipher); } catch (GeneralSecurityException e) { - throw (AssertionError)new AssertionError("Failed to create handshake ciphers").initCause(e); + throw new AssertionError("Failed to create handshake ciphers", e); } } diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpoint.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpoint.java index 5b6914fe4..38e18260b 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpoint.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpoint.java @@ -24,6 +24,11 @@ package org.jenkinsci.remoting.engine; import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; +import org.jenkinsci.remoting.util.KeyUtils; +import org.jenkinsci.remoting.util.ThrowableUtils; + +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; import java.io.BufferedInputStream; import java.io.BufferedReader; import java.io.IOException; @@ -38,10 +43,6 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import org.jenkinsci.remoting.util.KeyUtils; -import org.jenkinsci.remoting.util.ThrowableUtils; /** * Represents a {@code TcpSlaveAgentListener} endpoint details. @@ -215,7 +216,7 @@ public Socket open(int socketTimeout) throws IOException { if (isHttpProxy) { String connectCommand = String.format("CONNECT %s:%s HTTP/1.1\r\nHost: %s\r\n\r\n", host, port, host); socket.getOutputStream() - .write(connectCommand.getBytes("UTF-8")); // TODO: internationalized domain names + .write(connectCommand.getBytes(StandardCharsets.UTF_8)); // TODO: internationalized domain names BufferedInputStream is = new BufferedInputStream(socket.getInputStream()); BufferedReader reader = new BufferedReader(new InputStreamReader(is, StandardCharsets.UTF_8)); diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java index 094bb19d0..71b4f14d1 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpAgentEndpointResolver.java @@ -26,11 +26,16 @@ import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; import hudson.remoting.Launcher; import hudson.remoting.NoProxyEvaluator; - +import org.jenkinsci.remoting.util.VersionNumber; import org.jenkinsci.remoting.util.https.NoCheckHostnameVerifier; import org.jenkinsci.remoting.util.https.NoCheckTrustManager; -import org.jenkinsci.remoting.util.VersionNumber; +import javax.annotation.CheckForNull; +import javax.annotation.Nonnull; +import javax.net.ssl.HttpsURLConnection; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; import java.io.IOException; import java.net.ConnectException; import java.net.HttpURLConnection; @@ -45,23 +50,27 @@ import java.net.URI; import java.net.URL; import java.net.URLConnection; +import java.nio.charset.StandardCharsets; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.interfaces.RSAPublicKey; import java.security.spec.InvalidKeySpecException; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; import java.util.Base64; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.Set; +import java.util.StringJoiner; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Pattern; -import javax.annotation.CheckForNull; -import javax.annotation.Nonnull; -import javax.net.ssl.HttpsURLConnection; -import javax.net.ssl.SSLSocketFactory; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.TrustManager; import static java.util.logging.Level.INFO; import static org.jenkinsci.remoting.util.ThrowableUtils.chain; @@ -525,11 +534,11 @@ static URLConnection openURLConnection(URL url, String credentials, String proxy con = url.openConnection(); } if (credentials != null) { - String encoding = Base64.getEncoder().encodeToString(credentials.getBytes("UTF-8")); + String encoding = Base64.getEncoder().encodeToString(credentials.getBytes(StandardCharsets.UTF_8)); con.setRequestProperty("Authorization", "Basic " + encoding); } if (proxyCredentials != null) { - String encoding = Base64.getEncoder().encodeToString(proxyCredentials.getBytes("UTF-8")); + String encoding = Base64.getEncoder().encodeToString(proxyCredentials.getBytes(StandardCharsets.UTF_8)); con.setRequestProperty("Proxy-Authorization", "Basic " + encoding); } diff --git a/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol2Handler.java b/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol2Handler.java index f23b26b75..0c12a9eae 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol2Handler.java +++ b/src/main/java/org/jenkinsci/remoting/engine/JnlpProtocol2Handler.java @@ -24,6 +24,11 @@ package org.jenkinsci.remoting.engine; import hudson.remoting.Channel; +import org.jenkinsci.remoting.nio.NioChannelHub; +import org.jenkinsci.remoting.protocol.impl.ConnectionRefusalException; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.DataInputStream; @@ -31,6 +36,7 @@ import java.io.IOException; import java.io.PrintWriter; import java.net.Socket; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,10 +44,6 @@ import java.util.concurrent.ExecutorService; import java.util.logging.Level; import java.util.logging.Logger; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import org.jenkinsci.remoting.nio.NioChannelHub; -import org.jenkinsci.remoting.protocol.impl.ConnectionRefusalException; /** * Implementation of the JNLP2-connect protocol. @@ -151,7 +153,7 @@ void receiveHandshake(@Nonnull LegacyJnlpConnectionState state, @Nonnull Map properties = new HashMap(); properties.putAll((Map) request); String clientName = properties.get(JnlpConnectionState.CLIENT_NAME_KEY); diff --git a/src/main/java/org/jenkinsci/remoting/engine/LegacyJnlpConnectionState.java b/src/main/java/org/jenkinsci/remoting/engine/LegacyJnlpConnectionState.java index 1a0c4499f..f5f01141b 100644 --- a/src/main/java/org/jenkinsci/remoting/engine/LegacyJnlpConnectionState.java +++ b/src/main/java/org/jenkinsci/remoting/engine/LegacyJnlpConnectionState.java @@ -24,6 +24,7 @@ package org.jenkinsci.remoting.engine; import hudson.remoting.SocketChannelStream; + import java.io.BufferedOutputStream; import java.io.BufferedWriter; import java.io.DataInputStream; @@ -70,7 +71,7 @@ public LegacyJnlpConnectionState(Socket socket, List, Boolean> checked = new WeakHashMap<>(); /** @@ -62,7 +63,7 @@ public static void check(@Nonnull Class clazz) { } else { // May not call methods like Class#isAnonymousClass synchronously, since these can in turn trigger remote class loading. try { - channel.executor.submit((Runnable) () -> doCheck(clazz)); + channel.executor.submit(() -> doCheck(clazz)); } catch (RejectedExecutionException x) { // never mind, we tried } diff --git a/src/main/java/org/jenkinsci/remoting/util/VersionNumber.java b/src/main/java/org/jenkinsci/remoting/util/VersionNumber.java index f1f8f4550..9f7f64066 100644 --- a/src/main/java/org/jenkinsci/remoting/util/VersionNumber.java +++ b/src/main/java/org/jenkinsci/remoting/util/VersionNumber.java @@ -318,7 +318,7 @@ public int compare(Item item) { if (size() == 0) { return 0; // 1-0 = 1- (normalize) = 1 } - Item first = (Item) get(0); + Item first = get(0); return first.compare(null); } @@ -478,7 +478,7 @@ private void parseVersion(String version) { } private static Item parseItem(boolean isDigit, String buf) { - return isDigit ? (Item) new IntegerItem(buf) : (Item) new StringItem(buf, false); + return isDigit ? new IntegerItem(buf) : new StringItem(buf, false); } public int compareTo(VersionNumber o) { diff --git a/src/test/java/hudson/remoting/BinarySafeStreamTest.java b/src/test/java/hudson/remoting/BinarySafeStreamTest.java index b1da86005..3e806901c 100644 --- a/src/test/java/hudson/remoting/BinarySafeStreamTest.java +++ b/src/test/java/hudson/remoting/BinarySafeStreamTest.java @@ -30,6 +30,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.Base64; import java.util.Random; @@ -41,7 +42,7 @@ public class BinarySafeStreamTest extends TestCase { public void test1() throws IOException { ByteArrayOutputStream buf = new ByteArrayOutputStream(); OutputStream o = BinarySafeStream.wrap(buf); - byte[] data = "Sending some data to make sure it's encoded".getBytes("UTF-8"); + byte[] data = "Sending some data to make sure it's encoded".getBytes(StandardCharsets.UTF_8); o.write(data); o.close(); diff --git a/src/test/java/hudson/remoting/DeadRemoteOutputStreamTest.java b/src/test/java/hudson/remoting/DeadRemoteOutputStreamTest.java index 304064a1c..d6b8dab2c 100644 --- a/src/test/java/hudson/remoting/DeadRemoteOutputStreamTest.java +++ b/src/test/java/hudson/remoting/DeadRemoteOutputStreamTest.java @@ -20,7 +20,7 @@ public void testDeadWriterNotification() throws Exception { @Override public void write(int b) throws IOException { System.gc(); - throw (IOException)new IOException(MESSAGE).initCause((Exception) DummyClassLoader.apply(TestCallable.class)); + throw new IOException(MESSAGE, (Exception) DummyClassLoader.apply(TestCallable.class)); } }); diff --git a/src/test/java/hudson/remoting/DummyClassLoader.java b/src/test/java/hudson/remoting/DummyClassLoader.java index 87e79036b..697a09f9c 100644 --- a/src/test/java/hudson/remoting/DummyClassLoader.java +++ b/src/test/java/hudson/remoting/DummyClassLoader.java @@ -32,6 +32,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.net.URL; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -69,7 +70,7 @@ private byte[] loadTransformedClassImage() throws IOException { String data = IOUtils.toString(in, "ISO-8859-1"); // Single-character substitutions will not change length fields in bytecode etc. String data2 = data.replaceAll("remoting(.)Test", "rem0ting$1Test"); - return data2.getBytes("ISO-8859-1"); + return data2.getBytes(StandardCharsets.ISO_8859_1); } @Override diff --git a/src/test/java/hudson/remoting/RegExpBenchmark.java b/src/test/java/hudson/remoting/RegExpBenchmark.java index 7bd250b43..97ad4a194 100644 --- a/src/test/java/hudson/remoting/RegExpBenchmark.java +++ b/src/test/java/hudson/remoting/RegExpBenchmark.java @@ -23,6 +23,9 @@ */ package hudson.remoting; +import org.junit.Ignore; +import org.junit.Test; + import java.util.ArrayList; import java.util.Collections; import java.util.List; @@ -31,9 +34,6 @@ import java.util.jar.JarFile; import java.util.regex.Pattern; -import org.junit.Ignore; -import org.junit.Test; - @Ignore("This is not a test just a benchmark and is here for ease of running") public class RegExpBenchmark { @@ -82,9 +82,9 @@ public void benchmark() throws Exception { final List matchesString = checkClassesString(classes); final long durationStringNanos = System.nanoTime() - startString; - System.out.println(String.format(Locale.ENGLISH, "%-13s: %d blacklisted classes in %9dns. Average class check time is %dns", new Object[] {"RegExp ", matchesRegExp.size(), durationRegexpNanos, durationRegexpNanos/classes.size()})); - System.out.println(String.format(Locale.ENGLISH, "%-13s: %d blacklisted classes in %9dns. Average class check time is %dns", new Object[] {"SingleRegExp ", matchesSingleRegExp.size(), durationSingleRegexpNanos, durationSingleRegexpNanos/classes.size()})); - System.out.println(String.format(Locale.ENGLISH, "%-13s: %d blacklisted classes in %9dns. Average class check time is %dns", new Object[] {"String ", matchesString.size(), durationStringNanos, durationStringNanos/classes.size()})); + System.out.println(String.format(Locale.ENGLISH, "%-13s: %d blacklisted classes in %9dns. Average class check time is %dns", "RegExp ", matchesRegExp.size(), durationRegexpNanos, durationRegexpNanos/classes.size())); + System.out.println(String.format(Locale.ENGLISH, "%-13s: %d blacklisted classes in %9dns. Average class check time is %dns", "SingleRegExp ", matchesSingleRegExp.size(), durationSingleRegexpNanos, durationSingleRegexpNanos/classes.size())); + System.out.println(String.format(Locale.ENGLISH, "%-13s: %d blacklisted classes in %9dns. Average class check time is %dns", "String ", matchesString.size(), durationStringNanos, durationStringNanos/classes.size())); System.out.println("Regular Expression is " + durationRegexpNanos/durationStringNanos + " times slower"); System.out.println("Single Regular Expression is " + durationSingleRegexpNanos/durationStringNanos + " times slower\n"); @@ -138,9 +138,9 @@ private List getAllRTClasses() throws Exception { } jf.close(); // add in a couple from xalan and commons just for testing... - classes.add(new String("org.apache.commons.collections.functors.EvilClass")); - classes.add(new String("org.codehaus.groovy.runtime.IWIllHackYou")); - classes.add(new String("org.apache.xalan.YouAreOwned")); + classes.add("org.apache.commons.collections.functors.EvilClass"); + classes.add("org.codehaus.groovy.runtime.IWIllHackYou"); + classes.add("org.apache.xalan.YouAreOwned"); return classes; } } diff --git a/src/test/java/hudson/remoting/RemoteInputStreamTest.java b/src/test/java/hudson/remoting/RemoteInputStreamTest.java index d03c754db..6b7ddd9bc 100644 --- a/src/test/java/hudson/remoting/RemoteInputStreamTest.java +++ b/src/test/java/hudson/remoting/RemoteInputStreamTest.java @@ -9,9 +9,11 @@ import java.io.InputStream; import java.io.SequenceInputStream; import java.io.UnsupportedEncodingException; +import java.nio.charset.StandardCharsets; import java.util.Arrays; -import static hudson.remoting.RemoteInputStream.Flag.*; +import static hudson.remoting.RemoteInputStream.Flag.GREEDY; +import static hudson.remoting.RemoteInputStream.Flag.NOT_GREEDY; import static java.util.Arrays.asList; /** @@ -145,7 +147,7 @@ private static void assertEquals(byte[] b1, byte[] b2) throws IOException { } private static byte[] toBytes(String s) throws UnsupportedEncodingException { - return s.getBytes("UTF-8"); + return s.getBytes(StandardCharsets.UTF_8); } public static Test suite() throws Exception { diff --git a/src/test/java/hudson/remoting/SimpleTest.java b/src/test/java/hudson/remoting/SimpleTest.java index 839daa76e..60081bb79 100644 --- a/src/test/java/hudson/remoting/SimpleTest.java +++ b/src/test/java/hudson/remoting/SimpleTest.java @@ -23,9 +23,9 @@ */ package hudson.remoting; -import java.util.concurrent.CancellationException; import junit.framework.Test; +import java.util.concurrent.CancellationException; import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; @@ -90,7 +90,7 @@ public void test3() throws Exception { assertSame(c,r); } - public static interface Foo {} + public interface Foo {} private static class Echo extends CallableBase { private final T t; diff --git a/src/test/java/org/jenkinsci/remoting/nio/FifoBufferTest.java b/src/test/java/org/jenkinsci/remoting/nio/FifoBufferTest.java index a2b841908..0c81f13fa 100644 --- a/src/test/java/org/jenkinsci/remoting/nio/FifoBufferTest.java +++ b/src/test/java/org/jenkinsci/remoting/nio/FifoBufferTest.java @@ -11,6 +11,7 @@ import java.nio.channels.Channels; import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import java.nio.charset.StandardCharsets; /** * @author Kohsuke Kawaguchi @@ -115,7 +116,7 @@ private InputStream bs(String s) throws UnsupportedEncodingException { } private byte[] b(String s) throws UnsupportedEncodingException { - return s.getBytes("UTF-8"); + return s.getBytes(StandardCharsets.UTF_8); } private ByteBuffer bb(String s) throws UnsupportedEncodingException { diff --git a/src/test/java/org/jenkinsci/remoting/protocol/IOBufferMatcher.java b/src/test/java/org/jenkinsci/remoting/protocol/IOBufferMatcher.java index 710ce40b3..1e60c06c9 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/IOBufferMatcher.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/IOBufferMatcher.java @@ -25,13 +25,19 @@ import com.google.common.util.concurrent.SettableFuture; import edu.umd.cs.findbugs.annotations.NonNull; +import org.apache.commons.io.IOUtils; +import org.hamcrest.Matcher; + +import javax.annotation.CheckForNull; +import javax.annotation.CheckReturnValue; +import javax.annotation.Nonnull; import java.io.ByteArrayOutputStream; import java.io.Closeable; import java.io.IOException; -import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; import java.nio.channels.Channels; import java.nio.channels.WritableByteChannel; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.concurrent.CountDownLatch; @@ -43,12 +49,6 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.io.IOUtils; -import org.hamcrest.Matcher; - -import javax.annotation.CheckForNull; -import javax.annotation.CheckReturnValue; -import javax.annotation.Nonnull; /** * An {@link IOBufferMatcher} can {@link #send(ByteBuffer)} and {@link #receive(ByteBuffer)} streams of data as @@ -162,11 +162,7 @@ public byte[] asByteArray() { } public String asString() { - try { - return new String(asByteArray(), "UTF-8"); - } catch (UnsupportedEncodingException e) { - throw new IllegalStateException("JLS mandates UTF-8"); - } + return new String(asByteArray(), StandardCharsets.UTF_8); } @Override diff --git a/src/test/java/org/jenkinsci/remoting/protocol/IOHubTest.java b/src/test/java/org/jenkinsci/remoting/protocol/IOHubTest.java index c319da238..4184177d9 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/IOHubTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/IOHubTest.java @@ -23,6 +23,10 @@ */ package org.jenkinsci.remoting.protocol; +import org.apache.commons.io.IOUtils; +import org.junit.Rule; +import org.junit.Test; + import java.io.IOException; import java.net.InetSocketAddress; import java.net.Socket; @@ -32,15 +36,12 @@ import java.nio.channels.SelectionKey; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; -import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import org.apache.commons.io.IOUtils; -import org.junit.Rule; -import org.junit.Test; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; @@ -111,7 +112,7 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write) try { SocketChannel channel = srv.accept(); channel.write(ByteBuffer.wrap(String.format("Go away #%d", count.incrementAndGet()) - .getBytes(Charset.forName("UTF-8")))); + .getBytes(StandardCharsets.UTF_8))); channel.close(); } catch (IOException e) { // ignore @@ -163,7 +164,7 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write) try { SocketChannel channel = srv.accept(); channel.write(ByteBuffer.wrap(String.format("Go away #%d", count.incrementAndGet()) - .getBytes(Charset.forName("UTF-8")))); + .getBytes(StandardCharsets.UTF_8))); channel.close(); } catch (IOException e) { // ignore @@ -223,7 +224,7 @@ public void ready(boolean accept, boolean connect, boolean read, boolean write) try { SocketChannel channel = srv.accept(); channel.write(ByteBuffer.wrap(String.format("Go away #%d", count.incrementAndGet()) - .getBytes(Charset.forName("UTF-8")))); + .getBytes(StandardCharsets.UTF_8))); channel.close(); } catch (IOException e) { // ignore diff --git a/src/test/java/org/jenkinsci/remoting/protocol/ProtocolStackImplTest.java b/src/test/java/org/jenkinsci/remoting/protocol/ProtocolStackImplTest.java index fe9ed55e0..531664f38 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/ProtocolStackImplTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/ProtocolStackImplTest.java @@ -24,11 +24,7 @@ package org.jenkinsci.remoting.protocol; import hudson.remoting.Callable; -import java.io.OutputStream; -import java.nio.channels.ClosedChannelException; -import java.util.Collections; -import java.util.Map; -import java.util.concurrent.ExecutionException; +import hudson.remoting.Channel; import org.jenkinsci.remoting.RoleChecker; import org.jenkinsci.remoting.protocol.cert.RSAKeyPairRule; import org.jenkinsci.remoting.protocol.cert.SSLContextRule; @@ -40,26 +36,32 @@ import org.jenkinsci.remoting.protocol.impl.ConnectionRefusalException; import org.jenkinsci.remoting.protocol.impl.HoldFilterLayer; import org.jenkinsci.remoting.protocol.impl.NIONetworkLayer; -import hudson.remoting.Channel; +import org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.theories.Theory; +import org.junit.rules.RuleChain; +import org.junit.rules.TestName; +import org.junit.rules.Timeout; + +import javax.net.ssl.SSLEngine; import java.io.DataInputStream; import java.io.IOException; import java.io.InputStream; +import java.io.OutputStream; import java.net.InetSocketAddress; import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; import java.nio.channels.Pipe; import java.nio.channels.ServerSocketChannel; import java.nio.channels.SocketChannel; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.Map; +import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import javax.net.ssl.SSLEngine; -import org.jenkinsci.remoting.protocol.impl.SSLEngineFilterLayer; -import org.junit.ClassRule; -import org.junit.Rule; -import org.junit.Test; -import org.junit.experimental.theories.Theory; -import org.junit.rules.RuleChain; -import org.junit.rules.TestName; -import org.junit.rules.Timeout; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; @@ -93,7 +95,7 @@ public void basicReadthrough() throws Exception { ProtocolStack instance = ProtocolStack.on(new BIONetworkLayer(selector.hub(), input.source(), output.sink())) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -113,7 +115,7 @@ public void basicWritethrough() throws Exception { ProtocolStack instance = ProtocolStack.on(new BIONetworkLayer(selector.hub(), input.source(), output.sink())) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -207,7 +209,7 @@ public void pipeBasicBackToBack() throws Exception { ProtocolStack west = ProtocolStack.on(new BIONetworkLayer(selector.hub(), eastToWest.source(), westToEast.sink())) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -232,7 +234,7 @@ public void socketBasicBackToBack() throws Exception { ProtocolStack west = ProtocolStack.on(new BIONetworkLayer(selector.hub(), westChannel, westChannel)) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -258,7 +260,7 @@ public void pipeBasicBackToBackWithAck() throws Exception { .filter(new AckFilterLayer()) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -287,7 +289,7 @@ public void socketBasicBackToBackWithAck() throws Exception { .filter(new AckFilterLayer()) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -321,7 +323,7 @@ public void pipeBasicBackToBackWithAckSSLEngine() throws Exception { .filter(new SSLEngineFilterLayer(westEngine, null)) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -358,7 +360,7 @@ public void socketBasicBackToBackWithAckSSLEngine() throws Exception { .filter(new SSLEngineFilterLayer(westEngine, null)) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -408,7 +410,7 @@ public void onReceiveHeaders(Map headers) })) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -461,7 +463,7 @@ public void onReceiveHeaders(Map headers) })) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); diff --git a/src/test/java/org/jenkinsci/remoting/protocol/impl/AckFilterLayerTest.java b/src/test/java/org/jenkinsci/remoting/protocol/impl/AckFilterLayerTest.java index 0b56b7b8d..a77fd033c 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/impl/AckFilterLayerTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/impl/AckFilterLayerTest.java @@ -23,6 +23,7 @@ */ package org.jenkinsci.remoting.protocol.impl; +import org.apache.commons.io.IOUtils; import org.jenkinsci.remoting.protocol.IOBufferMatcher; import org.jenkinsci.remoting.protocol.IOBufferMatcherLayer; import org.jenkinsci.remoting.protocol.IOHubRule; @@ -30,10 +31,6 @@ import org.jenkinsci.remoting.protocol.ProtocolStack; import org.jenkinsci.remoting.protocol.Repeat; import org.jenkinsci.remoting.protocol.RepeatRule; -import java.nio.ByteBuffer; -import java.nio.channels.Pipe; -import java.util.concurrent.TimeUnit; -import org.apache.commons.io.IOUtils; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -45,6 +42,11 @@ import org.junit.rules.Timeout; import org.junit.runner.RunWith; +import java.nio.ByteBuffer; +import java.nio.channels.Pipe; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.TimeUnit; + import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -102,7 +104,7 @@ public void smokes(NetworkLayerFactory serverFactory, NetworkLayerFactory client .filter(new AckFilterLayer("ACK")) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); diff --git a/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersFilterLayerTest.java b/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersFilterLayerTest.java index 849c0bf75..e2f9cb3aa 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersFilterLayerTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersFilterLayerTest.java @@ -24,13 +24,6 @@ package org.jenkinsci.remoting.protocol.impl; import com.google.common.util.concurrent.SettableFuture; -import java.nio.ByteBuffer; -import java.nio.channels.Pipe; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.TimeUnit; import org.apache.commons.io.IOUtils; import org.jenkinsci.remoting.protocol.IOBufferMatcher; import org.jenkinsci.remoting.protocol.IOBufferMatcherLayer; @@ -49,6 +42,15 @@ import org.junit.rules.Timeout; import org.junit.runner.RunWith; +import java.nio.ByteBuffer; +import java.nio.channels.Pipe; +import java.nio.charset.StandardCharsets; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.TimeUnit; + import static org.hamcrest.Matchers.allOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; @@ -100,7 +102,7 @@ public void smokes(NetworkLayerFactory serverFactory, NetworkLayerFactory client ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -114,7 +116,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -124,7 +126,7 @@ public void onReceiveHeaders(Map headers) })) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); @@ -140,7 +142,7 @@ public void clientRejects(NetworkLayerFactory serverFactory, NetworkLayerFactory ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -154,7 +156,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -176,7 +178,7 @@ public void serverRejects(NetworkLayerFactory serverFactory, NetworkLayerFactory ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -190,7 +192,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -212,7 +214,7 @@ public void bothReject(NetworkLayerFactory serverFactory, NetworkLayerFactory cl ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -226,7 +228,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -252,7 +254,7 @@ public void clientRefuses(NetworkLayerFactory serverFactory, NetworkLayerFactory ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -266,7 +268,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -291,7 +293,7 @@ public void serverRefuses(NetworkLayerFactory serverFactory, NetworkLayerFactory ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -305,7 +307,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -330,7 +332,7 @@ public void bothRefuse(NetworkLayerFactory serverFactory, NetworkLayerFactory cl ProtocolStack client = ProtocolStack .on(clientFactory.create(selector.hub(), serverToClient.source(), clientToServer.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -344,7 +346,7 @@ public void onReceiveHeaders(Map headers) ProtocolStack server = ProtocolStack .on(serverFactory.create(selector.hub(), clientToServer.source(), serverToClient.sink())) - .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), + .filter(new ConnectionHeadersFilterLayer(Collections.emptyMap(), new ConnectionHeadersFilterLayer.Listener() { @Override public void onReceiveHeaders(Map headers) @@ -404,7 +406,7 @@ public void onReceiveHeaders(Map headers) })) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); diff --git a/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersTest.java b/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersTest.java index 726a40952..5b943f973 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/impl/ConnectionHeadersTest.java @@ -23,12 +23,13 @@ */ package org.jenkinsci.remoting.protocol.impl; +import org.junit.Test; + import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.util.Collections; import java.util.Map; import java.util.TreeMap; -import org.junit.Test; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.instanceOf; @@ -41,7 +42,7 @@ public class ConnectionHeadersTest { @Test public void emptyRoundTrip() throws Exception { - assertThat(ConnectionHeaders.fromString(ConnectionHeaders.toString(Collections.emptyMap())), + assertThat(ConnectionHeaders.fromString(ConnectionHeaders.toString(Collections.emptyMap())), is(Collections.emptyMap())); } diff --git a/src/test/java/org/jenkinsci/remoting/protocol/impl/NetworkLayerTest.java b/src/test/java/org/jenkinsci/remoting/protocol/impl/NetworkLayerTest.java index 09e94ea06..0a7ff2a08 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/impl/NetworkLayerTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/impl/NetworkLayerTest.java @@ -23,11 +23,6 @@ */ package org.jenkinsci.remoting.protocol.impl; -import java.nio.ByteBuffer; -import java.nio.channels.Pipe; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; - import org.apache.commons.io.IOUtils; import org.jenkinsci.remoting.protocol.IOBufferMatcher; import org.jenkinsci.remoting.protocol.IOBufferMatcherLayer; @@ -41,6 +36,12 @@ import org.junit.experimental.theories.Theory; import org.junit.runner.RunWith; +import java.nio.ByteBuffer; +import java.nio.channels.Pipe; +import java.nio.charset.StandardCharsets; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; + import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -93,7 +94,7 @@ public void doBasicSendReceive(NetworkLayerFactory serverFactory, NetworkLayerFa .on(serverFactory.create(hub, clientToServer.source(), serverToClient.sink())) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip(); diff --git a/src/test/java/org/jenkinsci/remoting/protocol/impl/SSLEngineFilterLayerTest.java b/src/test/java/org/jenkinsci/remoting/protocol/impl/SSLEngineFilterLayerTest.java index 09ccf7d61..8dfeb4705 100644 --- a/src/test/java/org/jenkinsci/remoting/protocol/impl/SSLEngineFilterLayerTest.java +++ b/src/test/java/org/jenkinsci/remoting/protocol/impl/SSLEngineFilterLayerTest.java @@ -23,19 +23,6 @@ */ package org.jenkinsci.remoting.protocol.impl; -import java.nio.ByteBuffer; -import java.nio.channels.ClosedChannelException; -import java.nio.channels.Pipe; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.SSLSession; import org.apache.commons.io.IOUtils; import org.jenkinsci.remoting.protocol.IOBufferMatcher; import org.jenkinsci.remoting.protocol.IOBufferMatcherLayer; @@ -60,6 +47,21 @@ import org.junit.rules.Timeout; import org.junit.runner.RunWith; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.SSLSession; +import java.nio.ByteBuffer; +import java.nio.channels.ClosedChannelException; +import java.nio.channels.Pipe; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.logging.Level; +import java.util.logging.Logger; + import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; @@ -199,7 +201,7 @@ public void smokes(NetworkLayerFactory serverFactory, NetworkLayerFactory client .filter(new SSLEngineFilterLayer(serverEngine, null)) .build(new IOBufferMatcherLayer()); - byte[] expected = "Here is some sample data".getBytes("UTF-8"); + byte[] expected = "Here is some sample data".getBytes(StandardCharsets.UTF_8); ByteBuffer data = ByteBuffer.allocate(expected.length); data.put(expected); data.flip();