8058464: (process spec) ProcessBuilder.redirectXXX throws unspecified NPE
Summary: Add a class level spec for null arguments throwing NPE in ProcessBuilder
Reviewed-by: martin, alanb
--- a/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java Tue Mar 10 13:30:21 2015 +0100
+++ b/jdk/src/java.base/share/classes/java/lang/ProcessBuilder.java Tue Mar 10 16:44:45 2015 -0400
@@ -171,6 +171,11 @@
* variables, first call {@link java.util.Map#clear() Map.clear()}
* before adding environment variables.
*
+ * <p>
+ * Unless otherwise noted, passing a {@code null} argument to a constructor
+ * or method in this class will cause a {@link NullPointerException} to be
+ * thrown.
+ *
* @author Martin Buchholz
* @since 1.5
*/
@@ -193,7 +198,6 @@
* command.
*
* @param command the list containing the program and its arguments
- * @throws NullPointerException if the argument is null
*/
public ProcessBuilder(List<String> command) {
if (command == null)
@@ -228,8 +232,6 @@
*
* @param command the list containing the program and its arguments
* @return this process builder
- *
- * @throws NullPointerException if the argument is null
*/
public ProcessBuilder command(List<String> command) {
if (command == null)
@@ -554,7 +556,6 @@
* }</pre>
*
* @param file The {@code File} for the {@code Redirect}.
- * @throws NullPointerException if the specified file is null
* @return a redirect to read from the specified file
*/
public static Redirect from(final File file) {
@@ -581,7 +582,6 @@
* }</pre>
*
* @param file The {@code File} for the {@code Redirect}.
- * @throws NullPointerException if the specified file is null
* @return a redirect to write to the specified file
*/
public static Redirect to(final File file) {
@@ -612,7 +612,6 @@
* }</pre>
*
* @param file The {@code File} for the {@code Redirect}.
- * @throws NullPointerException if the specified file is null
* @return a redirect to append to the specified file
*/
public static Redirect appendTo(final File file) {
--- a/jdk/test/java/lang/ProcessBuilder/Basic.java Tue Mar 10 13:30:21 2015 +0100
+++ b/jdk/test/java/lang/ProcessBuilder/Basic.java Tue Mar 10 16:44:45 2015 -0400
@@ -26,7 +26,7 @@
* @bug 4199068 4738465 4937983 4930681 4926230 4931433 4932663 4986689
* 5026830 5023243 5070673 4052517 4811767 6192449 6397034 6413313
* 6464154 6523983 6206031 4960438 6631352 6631966 6850957 6850958
- * 4947220 7018606 7034570 4244896 5049299 8003488 8054494
+ * 4947220 7018606 7034570 4244896 5049299 8003488 8054494 8058464
* @summary Basic tests for Process and Environment Variable code
* @run main/othervm/timeout=300 Basic
* @run main/othervm/timeout=300 -Djdk.lang.Process.launchMechanism=fork Basic
@@ -941,6 +941,14 @@
() -> pb.redirectOutput(Redirect.from(ifile)),
() -> pb.redirectError(Redirect.from(ifile)));
+ THROWS(NullPointerException.class,
+ () -> pb.redirectInput((File)null),
+ () -> pb.redirectOutput((File)null),
+ () -> pb.redirectError((File)null),
+ () -> pb.redirectInput((Redirect)null),
+ () -> pb.redirectOutput((Redirect)null),
+ () -> pb.redirectError((Redirect)null));
+
THROWS(IOException.class,
// Input file does not exist
() -> pb.start());