Uploaded image for project: 'Jenkins'
  1. Jenkins
  2. JENKINS-59844

Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command

    • Icon: Improvement Improvement
    • Resolution: Unresolved
    • Icon: Minor Minor
    • core
    • Oracle JRE 8 and 11
      Jenkins 2.190.1

      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:

      java.lang.ArrayIndexOutOfBoundsException: 0
      	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1014)
      	at hudson.Proc$LocalProc.<init>(Proc.java:249)
      	at hudson.Proc$LocalProc.<init>(Proc.java:218)
      	at hudson.Launcher$LocalLauncher.launch(Launcher.java:930)
      	at hudson.Launcher$ProcStarter.start(Launcher.java:450)
      	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1299)
      	at hudson.Launcher$RemoteLaunchCallable.call(Launcher.java:1260)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:205)
      	at hudson.remoting.UserRequest.perform(UserRequest.java:52)
      	at hudson.remoting.Request$2.run(Request.java:356)
      	at hudson.remoting.InterceptingExecutorService$1.call(InterceptingExecutorService.java:72)
      	at java.util.concurrent.FutureTask.run(FutureTask.java:266)
      	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
      	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
      	at java.lang.Thread.run(Thread.java:748)
      

      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.

          [JENKINS-59844] Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command

          Hi - I will like to work on this. However, I am unable to reporduce the issue. Can you please provide the steps to reproduce?

          Dishit Devasia added a comment - Hi - I will like to work on this. However, I am unable to reporduce the issue. Can you please provide the steps to reproduce?

          Esther Álvarez Feijoo added a comment - - edited

          Esther Álvarez Feijoo added a comment - - edited Here you have a test to reproduce it: https://github.com/EstherAF/jenkins/commit/198e0a22c326f7d5a1c130deb56063592e646d41

          Ramon Leon added a comment -

          dishitd I've been working on it for a while. Are you fine if I take care of it?

          Ramon Leon added a comment - dishitd I've been working on it for a while. Are you fine if I take care of it?

          Sure go ahead

          Dishit Devasia added a comment - Sure go ahead

          Ramon Leon added a comment - - edited

          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.

          Ramon Leon added a comment - - edited 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.

          Ramon Leon added a comment -

          Not sure about the right final status of the ticket

          Ramon Leon added a comment - 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.

          Esther Álvarez Feijoo added a comment - 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.

          Ramon Leon added a comment -

          Ramon Leon added a comment - It's documented: https://docs.oracle.com/javase/8/docs/api/java/lang/ProcessBuilder.html#start--

          After talking with mramonleon, we agreed that:

          • Given that the exception is documented in downstream jdk class (ProcessBuilder), it can have been handled already by some client, so changing this exception for another can have unexpected consequences in any plugin using hudson.Launcher
          • ProcessBuilder is being used in several other classes in jenkins. To be consistent we should handle this exception equally, increasing the number of interface changes.

          The objective is to make clearer the cause of this exception, so the least risky solution is:

          • Showing a log before invoking the Launcher, when the command is empty, informing the user that this can cause unexpected behaviour.
            This should help any user to track down the cause of this exception in the future.
          • Complete Launcher's javadoc informing about that a RuntimeException can be thrown because of that reason.

          I'm creating a PR with these little changes

          Esther Álvarez Feijoo added a comment - After talking with mramonleon , we agreed that: Given that the exception is documented in downstream jdk class (ProcessBuilder), it can have been handled already by some client, so changing this exception for another can have unexpected consequences in any plugin using hudson.Launcher ProcessBuilder is being used in several other classes in jenkins. To be consistent we should handle this exception equally, increasing the number of interface changes. The objective is to make clearer the cause of this exception, so the least risky solution is: Showing a log before invoking the Launcher, when the command is empty, informing the user that this can cause unexpected behaviour. This should help any user to track down the cause of this exception in the future. Complete Launcher's javadoc informing about that a RuntimeException can be thrown because of that reason. I'm creating a PR with these little changes

            Unassigned Unassigned
            ealvarez Esther Álvarez Feijoo
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: