Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-4095714

Runtime.exec(String[] cmdarray) works wrong with empty array

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • P3
    • 1.2.0
    • 1.1.4
    • core-libs
    • 1.2beta4
    • sparc
    • solaris_2.5
    • Verified

    Description



      Name: dsC58869 Date: 11/27/97



      The method java.lang.Runtime.exec(String[] cmdarray, String envp[]) works
      wrong with empty array.
      It throws NullPointerException instead of IndexOutOfBoundsException

      The Java Language Specification say
      >20.16.6 public Process exec(String cmdarray[], String envp[])
      >throws IOException, SecurityException,
      >NullPointerException, IndexOutOfBoundsException
      >
      >First, if there is a security manager, its checkExec method (§20.17.14) is called with
      >the first component of the array cmdarray as its argument.
      >
      >If cmdarray is null, a NullPointerException is thrown. If cmdarray is an
      ^^^^^^^^^^^^^^^^^
      >empty array (has length 0), an IndexOutOfBoundsException is thrown.
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

      ==== Here is the test demonstrating the bug ====

      public class Test{
          public static void main(String[] args){
      Runtime rt = Runtime.getRuntime();
            try{
              String[] strs = new String[0];
             rt.exec(strs);
            } catch (java.io.IOException io) {
             System.out.println("Failed:" + io);
            } catch (IndexOutOfBoundsException e){
             System.out.println("OKAY:" + e);
            } catch (NullPointerException npe) {
             System.out.println("Failed:" + npe);
            }
          }
      }

      ==== Here is the output of the test ====

      C:\home\sda\tmp>java Test
      Failed:java.lang.NullPointerException

      ======================================================================

      ======================================================================

      Attachments

        Activity

          People

            hongzh Hong Zhang
            dsilaev Dmitri Silaev
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: