Running non-existing jar does not cause any expection/error

Posted by Nikolay Kuznetsov on Stack Overflow See other posts from Stack Overflow or by Nikolay Kuznetsov
Published on 2012-12-10T10:57:39Z Indexed on 2012/12/10 11:04 UTC
Read the original article Hit count: 255

Filed under:
|
|
|

Please, consider the following snippet which is being run from Eclipse.

Even though the external jar file does not exist no Exception is thrown and process is not null. Why is it so?

try {
    Process process = Runtime.getRuntime().exec("java -jar NonExisting.jar");

    if (process == null)
            System.out.println("process = null");
    else
        System.out.println(process);
     } catch (IOException e) {
         System.err.println(e);
}

It prints

java.lang.ProcessImpl@1a4d139

If I run it manully from command line then there is an error:

C:\Users\workspace\Project\src>java -jar NonExisting.jar
Error: Unable to access jarfile NonExisting.jar

© Stack Overflow or respective owner

Related posts about java

Related posts about exception