Open timja opened 4 years ago
Hi - I will like to work on this. However, I am unable to reporduce the issue. Can you please provide the steps to reproduce?
Here you have a test to reproduce it:
https://github.com/EstherAF/jenkins/commit/198e0a22c326f7d5a1c130deb56063592e646d41
dishitd I've been working on it for a while. Are you fine if I take care of it?
The documentation of the ProcessBuilder class specified that the start method will return an IndexOutOfBoundsException if the command is the empty string, see the documentation here: https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html#start--
IndexOutOfBoundsException - if the command is an empty list (has size 0)
So the behavior is the expected. The code sending this command is the one in charge to avoid that or capture the exception properly.
I will close this ticket becase as it is described, there is nothing to do generally.
Not sure about the right final status of the ticket
If this exception is expected, it is my understanding that its meaning should be documented, to allow the client to proactively check this failing condition.
After talking with mramonleon, we agreed that:
The objective is to make clearer the cause of this exception, so the least risky solution is:
I'm creating a PR with these little changes
If you try to launch a blank command (' ') using Launch.ProcStarter#cmdAsSingleString, an ArrayIndexOutOfBoundException is thrown.
Example of command invocation:
launcher.launch() .cmdAsSingleString(" ") .envs(computer.getEnvironment()) .readStdout() .pwd(rootPath) .start();
Exception thrown:
This exception is odd, and difficult to understand. In my understanding, the cause of the error (invalid command) should be more clear, and ideally, validated sooner.
Originally reported by ealvarez, imported from: Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command