Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cleanup some test warnings and deprecated code #369

Merged
merged 6 commits into from
Mar 25, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/main/java/hudson/remoting/FileSystemJarCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public FileSystemJarCache(@Nonnull File rootDir, boolean touch) {
throw new IllegalArgumentException("Root directory is null");

try {
Util.mkdirs(rootDir);
Files.createDirectories(rootDir.toPath());
} catch (IOException ex) {
throw new IllegalArgumentException("Root directory not writable: " + rootDir, ex);
}
Expand Down Expand Up @@ -175,7 +175,7 @@ private Checksum fileChecksum(File file) throws IOException {
@SuppressFBWarnings(value = "PATH_TRAVERSAL_IN", justification = "This path exists within a temp directory so the potential traversal is limited.")
/*package for testing*/ File createTempJar(@Nonnull File target) throws IOException {
File parent = target.getParentFile();
Util.mkdirs(parent);
Files.createDirectories(parent.toPath());
return File.createTempFile(target.getName(), "tmp", parent);
}

Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/jenkinsci/remoting/util/KeyUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.security.Key;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import javax.annotation.CheckForNull;
import javax.annotation.Nonnull;

Expand Down
15 changes: 8 additions & 7 deletions src/test/java/JarCertDump.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@
*/
public class JarCertDump {
public static void main(String[] args) throws IOException {
JarFile j = new JarFile(new File(args[0]));
JarEntry je = j.getJarEntry("hudson/remoting/Channel.class");
if (je==null) throw new IllegalArgumentException();
IOUtils.readLines(j.getInputStream(je));
for (Certificate c : je.getCertificates()) {
System.out.println("################# Certificate #################");
System.out.println(c);
try (JarFile j = new JarFile(new File(args[0]))) {
JarEntry je = j.getJarEntry("hudson/remoting/Channel.class");
if (je==null) throw new IllegalArgumentException();
IOUtils.readLines(j.getInputStream(je));
for (Certificate c : je.getCertificates()) {
System.out.println("################# Certificate #################");
System.out.println(c);
}
}
}
}
1 change: 1 addition & 0 deletions src/test/java/hudson/remoting/CallableBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ public void checkRoles(RoleChecker checker) throws SecurityException {
}

public static final Role ROLE = new Role("test callable");
private static final long serialVersionUID = 1L;
}
3 changes: 3 additions & 0 deletions src/test/java/hudson/remoting/ChannelFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public CallableCallable(Callable c) {
public Object call() throws Exception {
return c.call();
}
private static final long serialVersionUID = 1L;
}

public void testBlacklisting() throws Exception {
Expand Down Expand Up @@ -91,11 +92,13 @@ static class GunImporter extends CallableBase<String,IOException> implements Sha
public String call() {
return "gun";
}
private static final long serialVersionUID = 1L;
}

static class ReverseGunImporter extends CallableBase<String, Exception> {
public String call() throws Exception {
return Channel.currentOrFail().call(new GunImporter());
}
private static final long serialVersionUID = 1L;
}
}
8 changes: 6 additions & 2 deletions src/test/java/hudson/remoting/ChannelTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.annotation.Nonnull;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;

import org.jenkinsci.remoting.RoleChecker;
import org.jvnet.hudson.test.Issue;
Expand Down Expand Up @@ -53,6 +51,7 @@ public Object call() throws IOException {
private void readObject(ObjectInputStream ois) throws IOException, ClassNotFoundException {
throw new ClassCastException("foobar");
}
private static final long serialVersionUID = 1L;
}

/**
Expand Down Expand Up @@ -130,6 +129,7 @@ public Void call() throws Exception {
getChannelOrFail().setProperty("foo","bar");
return null;
}
private static final long serialVersionUID = 1L;
}

public interface Greeter {
Expand Down Expand Up @@ -158,6 +158,7 @@ public Object call() throws IOException {
g.greet("Kohsuke");
return null;
}
private static final long serialVersionUID = 1L;
}


Expand All @@ -177,6 +178,7 @@ private static class Echo<T> extends CallableBase<T,RuntimeException> {
public T call() throws RuntimeException {
return t;
}
private static final long serialVersionUID = 1L;
}

@Bug(39150)
Expand Down Expand Up @@ -221,6 +223,7 @@ private static class ThrowingCallable extends CallableBase<Void, IOException> {
@Override public Void call() throws IOException {
throw new IOException("Node Nested", new RuntimeException("Node says hello!"));
}
private static final long serialVersionUID = 1L;
}

/**
Expand Down Expand Up @@ -294,6 +297,7 @@ public TInterface call() throws Exception {
public void checkRoles(RoleChecker checker) throws SecurityException {

}
private static final long serialVersionUID = 1L;
}

private static final class NeverEverCallable implements Callable<Void, Exception> {
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/hudson/remoting/ChecksumTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@
import java.io.ByteArrayInputStream;
import java.io.DataInputStream;
import java.io.File;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotEquals;

/**
Expand Down
3 changes: 3 additions & 0 deletions src/test/java/hudson/remoting/ClassFilterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ protected void execute(Channel channel) {
public String toString() {
return "Security218";
}
private static final long serialVersionUID = 1L;
}

private String getAttack() {
Expand All @@ -288,5 +289,7 @@ public Void call() throws IOException {
a.toString(); // this will ensure 'a' gets sent over
return null;
}
private static final long serialVersionUID = 1L;
}
private static final long serialVersionUID = 1L;
}
2 changes: 2 additions & 0 deletions src/test/java/hudson/remoting/DeadRemoteOutputStreamTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,7 @@ public Void call() throws Exception {
}
return null;
}
private static final long serialVersionUID = 1L;
}
private static final long serialVersionUID = 1L;
}
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ private void verify(ClassicCommandTransport ct) throws IOException, ClassNotFoun
@Test(timeout=3000)
public void blockingStreamShouldNotPreventDiagnosis() throws Exception {
FastPipedInputStream in = new FastPipedInputStream();
FastPipedOutputStream out = new FastPipedOutputStream(in);
out.write(payload);
try (FastPipedOutputStream out = new FastPipedOutputStream(in)) {
res0nance marked this conversation as resolved.
Show resolved Hide resolved
out.write(payload);
}

ClassicCommandTransport ct = (ClassicCommandTransport)
new ChannelBuilder("dummy",null)
Expand Down
1 change: 0 additions & 1 deletion src/test/java/hudson/remoting/NoProxyEvaluatorTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package hudson.remoting;

import org.junit.Ignore;
import org.junit.Test;

import static org.junit.Assert.*;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,16 +49,19 @@ public void test1() throws Throwable {
}

private static final class NoneSerializableException extends Exception {
@SuppressWarnings("unused")
private final Object o = new Object(); // this is not serializable

private NoneSerializableException(String msg, Throwable cause) {
super(msg, cause);
}
private static final long serialVersionUID = 1L;
}

private static final class Failure extends CallableBase {
private static final class Failure extends CallableBase<Object, Throwable> {
public Object call() throws Throwable {
throw new NoneSerializableException("message1",new SocketException("message2"));
}
private static final long serialVersionUID = 1L;
}
}
9 changes: 7 additions & 2 deletions src/test/java/hudson/remoting/PipeTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public Void call() throws Exception {
Thread.sleep(10);
}
}
private static final long serialVersionUID = 1L;
}

private static class WritingCallable extends CallableBase<Integer, IOException> {
Expand All @@ -112,6 +113,7 @@ public Integer call() throws IOException {
write(pipe);
return 5;
}
private static final long serialVersionUID = 1L;
}

/**
Expand Down Expand Up @@ -212,6 +214,7 @@ public void readRest() throws IOException {
}
});
}
private static final long serialVersionUID = 1L;
}

private static class ReadingCallable extends CallableBase<Integer, IOException> {
Expand All @@ -230,7 +233,7 @@ public Integer call() throws IOException {
}
return 5;
}

private static final long serialVersionUID = 1L;
}

private static void write(Pipe pipe) throws IOException {
Expand Down Expand Up @@ -281,7 +284,7 @@ private static class DevNullSink extends CallableBase<OutputStream, IOException>
public OutputStream call() throws IOException {
return new RemoteOutputStream(new NullOutputStream());
}

private static final long serialVersionUID = 1L;
}

public static Test suite() throws Exception {
Expand All @@ -304,5 +307,7 @@ public Integer call() throws IOException {
IOUtils.copy(p.getIn(), baos);
return baos.size();
}
private static final long serialVersionUID = 1L;
}
private static final long serialVersionUID = 1L;
}
9 changes: 9 additions & 0 deletions src/test/java/hudson/remoting/PipeWriterTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ public void run() {
* This is where the actual I/O happens.
*/
abstract void touch() throws IOException;
private static final long serialVersionUID = 1L;
}

/**
Expand Down Expand Up @@ -116,6 +117,7 @@ public Object call() throws IOException {
* This is where the actual I/O happens.
*/
abstract void touch() throws IOException;
private static final long serialVersionUID = 1L;
}

public void testRequestIoCoord() throws Exception {
Expand Down Expand Up @@ -180,35 +182,42 @@ private class ResponseCallableWriter extends ResponseIoCoordCallable {
void touch() throws IOException {
ros.write(0);
}
private static final long serialVersionUID = 1L;
}

private class ResponseCallableFlusher extends ResponseIoCoordCallable {
void touch() throws IOException {
ros.flush();
}
private static final long serialVersionUID = 1L;
}

private class ResponseCallableCloser extends ResponseIoCoordCallable {
void touch() throws IOException {
ros.close();
}
private static final long serialVersionUID = 1L;
}

private class RequestCallableWriter extends RequestIoCoordCallable {
void touch() throws IOException {
ros.write(0);
}
private static final long serialVersionUID = 1L;
}

private class RequestCallableFlusher extends RequestIoCoordCallable {
void touch() throws IOException {
ros.flush();
}
private static final long serialVersionUID = 1L;
}

private class RequestCallableCloser extends RequestIoCoordCallable {
void touch() throws IOException {
ros.close();
}
private static final long serialVersionUID = 1L;
}
private static final long serialVersionUID = 1L;
}
1 change: 1 addition & 0 deletions src/test/java/hudson/remoting/PrefetchTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,6 @@ public String call() throws IOException {
StackMapAttribute sma = new StackMapAttribute();
return Which.jarFile(sma.getClass()).getPath();
}
private static final long serialVersionUID = 1L;
}
}
7 changes: 6 additions & 1 deletion src/test/java/hudson/remoting/PrefetchingTest.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package hudson.remoting;
package hudson.remoting;

import com.google.common.base.Function;
import com.google.common.base.Predicate;
Expand Down Expand Up @@ -107,6 +107,7 @@ public Object apply(Object o) {
throw new Error(e);
}
}
private static final long serialVersionUID = 1L;
}

public void testGetResource() throws Exception {
Expand Down Expand Up @@ -201,6 +202,7 @@ private static final class Echo<V> extends CallableBase<V,IOException> implement
public V call() throws IOException {
return value;
}
private static final long serialVersionUID = 1L;
}

/**
Expand Down Expand Up @@ -229,12 +231,15 @@ public Void call() throws IOException {
throw new IOException(e);
}
}
private static final long serialVersionUID = 1L;
}

private class JarCacherCallable extends CallableBase<Void, IOException> {
public Void call() throws IOException {
Channel.currentOrFail().setJarCache(new FileSystemJarCache(dir, true));
return null;
}
private static final long serialVersionUID = 1L;
}
private static final long serialVersionUID = 1L;
}
5 changes: 4 additions & 1 deletion src/test/java/hudson/remoting/ProxyWriterTest.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package hudson.remoting;

import junit.framework.Test;
import org.junit.Assume;
import org.jvnet.hudson.test.Bug;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -146,6 +145,7 @@ public Void call() throws IOException {
writeBunchOfData(w);
return null;
}
private static final long serialVersionUID = 1L;
}

private static class WeakReferenceCallable extends CallableBase<Void, IOException> {
Expand All @@ -167,6 +167,7 @@ public Boolean call() throws IOException {
System.gc();
return W.get() == null;
}
private static final long serialVersionUID = 1L;
}

private static class WriterCallable extends CallableBase<Void, IOException> {
Expand All @@ -180,5 +181,7 @@ public Void call() throws IOException {
w.write("1--", 0, 1);
return null;
}
private static final long serialVersionUID = 1L;
}
private static final long serialVersionUID = 1L;
}
Loading