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
======================================================================
======================================================================