changeset 11585:6182e044b781

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
author rriggs
date Tue, 10 Mar 2015 16:44:45 -0400
parents 861eac6cf4a6
children 3e1171c96a99
files src/java.base/share/classes/java/lang/ProcessBuilder.java test/java/lang/ProcessBuilder/Basic.java
diffstat 2 files changed, 14 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.base/share/classes/java/lang/ProcessBuilder.java	Tue Mar 10 13:30:21 2015 +0100
+++ b/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/test/java/lang/ProcessBuilder/Basic.java	Tue Mar 10 13:30:21 2015 +0100
+++ b/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());