Skip to content

Commit

Permalink
Deprecate hudson.util.NullStream (#8128)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Jun 14, 2023
1 parent 9be693d commit ffd2afe
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 19 deletions.
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/Proc.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import hudson.util.DaemonThreadFactory;
import hudson.util.ExceptionCatchingThreadFactory;
import hudson.util.NamingThreadFactory;
import hudson.util.NullStream;
import hudson.util.ProcessTree;
import hudson.util.StreamCopyThread;
import java.io.File;
Expand Down Expand Up @@ -429,7 +428,7 @@ private static String calcName(String[] cmd) {
}

public static final InputStream SELFPUMP_INPUT = new NullInputStream(0);
public static final OutputStream SELFPUMP_OUTPUT = new NullStream();
public static final OutputStream SELFPUMP_OUTPUT = OutputStream.nullOutputStream();
}

/**
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/model/JDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,11 @@
import hudson.tools.ToolInstaller;
import hudson.tools.ToolProperty;
import hudson.util.FormValidation;
import hudson.util.NullStream;
import hudson.util.StreamTaskListener;
import hudson.util.XStream2;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.reflect.Constructor;
import java.util.Arrays;
import java.util.Collections;
Expand Down Expand Up @@ -164,7 +164,7 @@ public JDK forEnvironment(EnvVars environment) {
*/
public static boolean isDefaultJDKValid(Node n) {
try {
TaskListener listener = new StreamTaskListener(new NullStream());
TaskListener listener = new StreamTaskListener(OutputStream.nullOutputStream());
Launcher launcher = n.createLauncher(listener);
return launcher.launch().cmds("java", "-fullversion").stdout(listener).join() == 0;
} catch (IOException | InterruptedException e) {
Expand Down
3 changes: 1 addition & 2 deletions core/src/main/java/hudson/slaves/SlaveComputer.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@
import hudson.security.ACLContext;
import hudson.slaves.OfflineCause.ChannelTermination;
import hudson.util.Futures;
import hudson.util.NullStream;
import hudson.util.RingBufferLogHandler;
import hudson.util.StreamTaskListener;
import hudson.util.VersionNumber;
Expand Down Expand Up @@ -386,7 +385,7 @@ public OutputStream openLogFile() {
return log;
} catch (IOException e) {
logger.log(Level.SEVERE, "Failed to create log file " + getLogFile(), e);
return new NullStream();
return OutputStream.nullOutputStream();
}
}

Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/hudson/tasks/Maven.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,14 @@
import hudson.tools.ToolProperty;
import hudson.util.ArgumentListBuilder;
import hudson.util.FormValidation;
import hudson.util.NullStream;
import hudson.util.StreamTaskListener;
import hudson.util.VariableResolver;
import hudson.util.VariableResolver.ByMap;
import hudson.util.VariableResolver.Union;
import hudson.util.XStream2;
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -665,7 +665,7 @@ private static File getExeFile(String execName, String home) {
*/
public boolean getExists() {
try {
return getExecutable(new LocalLauncher(new StreamTaskListener(new NullStream()))) != null;
return getExecutable(new LocalLauncher(new StreamTaskListener(OutputStream.nullOutputStream()))) != null;
} catch (IOException | InterruptedException e) {
return false;
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/hudson/util/IOUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ public class IOUtils {
* Drains the input stream and closes it.
*/
public static void drain(InputStream in) throws IOException {
org.apache.commons.io.IOUtils.copy(in, new NullStream());
in.close();
try (in; OutputStream out = OutputStream.nullOutputStream()) {
org.apache.commons.io.IOUtils.copy(in, out);
}
}

public static void copy(File src, OutputStream out) throws IOException {
Expand Down
2 changes: 2 additions & 0 deletions core/src/main/java/hudson/util/NullStream.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

/**
* @author Kohsuke Kawaguchi
* @deprecated use {@link OutputStream#nullOutputStream}
*/
@Deprecated
public final class NullStream extends OutputStream {
public NullStream() {}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/hudson/util/StreamTaskListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ public StreamTaskListener(@NonNull Writer w) throws IOException {
*/
@Deprecated
public StreamTaskListener() throws IOException {
this(new NullStream());
this(OutputStream.nullOutputStream());
}

public static StreamTaskListener fromStdout() {
Expand Down
12 changes: 7 additions & 5 deletions core/src/test/java/hudson/FilePathTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@
import hudson.os.WindowsUtil;
import hudson.remoting.VirtualChannel;
import hudson.slaves.WorkspaceList;
import hudson.util.NullStream;
import hudson.util.StreamTaskListener;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -78,7 +77,6 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.output.NullOutputStream;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.Chmod;
import org.junit.Ignore;
Expand All @@ -99,7 +97,9 @@ public class FilePathTest {
@Test public void copyTo() throws Exception {
File tmp = temp.newFile();
FilePath f = new FilePath(channels.french, tmp.getPath());
f.copyTo(new NullStream());
try (OutputStream out = OutputStream.nullOutputStream()) {
f.copyTo(out);
}
assertTrue("target does not exist", tmp.exists());
assertTrue("could not delete target " + tmp.getPath(), tmp.delete());
}
Expand Down Expand Up @@ -260,8 +260,10 @@ public void close() {
@Test public void archiveBug() throws Exception {
FilePath d = new FilePath(channels.french, temp.getRoot().getPath());
d.child("test").touch(0);
d.zip(NullOutputStream.NULL_OUTPUT_STREAM);
d.zip(NullOutputStream.NULL_OUTPUT_STREAM, "**/*");
try (OutputStream out = OutputStream.nullOutputStream()) {
d.zip(out);
d.zip(out, "**/*");
}
}

@Test public void normalization() {
Expand Down
9 changes: 6 additions & 3 deletions core/src/test/java/hudson/util/io/TarArchiverTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import hudson.Launcher.LocalLauncher;
import hudson.Util;
import hudson.model.TaskListener;
import hudson.util.NullStream;
import hudson.util.StreamTaskListener;
import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -117,7 +116,9 @@ private static void run(FilePath dir, String... cmds) throws InterruptedExceptio
assumeFalse(Functions.isWindows());
File dir = tmp.getRoot();
Util.createSymlink(dir, "nonexistent", "link", TaskListener.NULL);
new FilePath(dir).tar(new NullStream(), "**");
try (OutputStream out = OutputStream.nullOutputStream()) {
new FilePath(dir).tar(out, "**");
}
}


Expand All @@ -132,7 +133,9 @@ private static void run(FilePath dir, String... cmds) throws InterruptedExceptio
Thread t1 = new Thread(runnable1);
t1.start();

new FilePath(tmp.getRoot()).tar(new NullStream(), "**");
try (OutputStream out = OutputStream.nullOutputStream()) {
new FilePath(tmp.getRoot()).tar(out, "**");
}

runnable1.doFinish();
t1.join();
Expand Down

0 comments on commit ffd2afe

Please sign in to comment.