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

53 views
Skip to first unread message

ealvarez@cloudbees.com (JIRA)

unread,
Oct 18, 2019, 9:04:03 AM10/18/19
to jenkinsc...@googlegroups.com
Esther Álvarez Feijoo created an issue
 
Jenkins / Improvement JENKINS-59844
Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command
Issue Type: Improvement Improvement
Assignee: Unassigned
Components: core
Created: 2019-10-18 13:03
Environment: Oracle JRE 8 and 11
Jenkins 2.190.1
Priority: Minor Minor
Reporter: Esther Álvarez Feijoo

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.

Add Comment Add Comment
 
This message was sent by Atlassian Jira (v7.13.6#713006-sha1:cc4451f)
Atlassian logo

dbeck@cloudbees.com (JIRA)

unread,
Oct 18, 2019, 9:27:01 AM10/18/19
to jenkinsc...@googlegroups.com

dishid@gmail.com (JIRA)

unread,
Oct 18, 2019, 9:05:03 PM10/18/19
to jenkinsc...@googlegroups.com
Dishit Devasia commented on Improvement JENKINS-59844
 
Re: 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?

ealvarez@cloudbees.com (JIRA)

unread,
Oct 21, 2019, 6:18:05 AM10/21/19
to jenkinsc...@googlegroups.com

ealvarez@cloudbees.com (JIRA)

unread,
Oct 21, 2019, 6:19:02 AM10/21/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 21, 2019, 6:26:03 AM10/21/19
to jenkinsc...@googlegroups.com

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

dishid@gmail.com (JIRA)

unread,
Oct 21, 2019, 5:13:03 PM10/21/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:40:03 AM10/22/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:40:03 AM10/22/19
to jenkinsc...@googlegroups.com
Ramon Leon started work on Improvement JENKINS-59844
 
Change By: Ramon Leon
Status: Open In Progress

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:41:02 AM10/22/19
to jenkinsc...@googlegroups.com
Ramon Leon commented on Improvement JENKINS-59844
 
Re: Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command

If a NodeProperty implementer throws an exception in its canTake method, the queue stops working. Changed the priority to Major

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:51:03 AM10/22/19
to jenkinsc...@googlegroups.com
Ramon Leon updated an issue
Change By: Ramon Leon
Comment: If a NodeProperty implementer throws an exception in its canTake method, the queue stops working. Changed the priority to *Major*

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:51:03 AM10/22/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:51:03 AM10/22/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:55:03 AM10/22/19
to jenkinsc...@googlegroups.com
 
Re: Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command

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

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.

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:56:03 AM10/22/19
to jenkinsc...@googlegroups.com
Ramon Leon edited a comment on Improvement JENKINS-59844
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--]
{quote}{{[IndexOutOfBoundsException|https://docs.oracle.com/javase/8/docs/api/java/lang/IndexOutOfBoundsException.html]}} - if the command is an empty list (has size {{0}})
{quote}
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.

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:57:05 AM10/22/19
to jenkinsc...@googlegroups.com
Change By: Ramon Leon
Status: In Progress Fixed but Unreleased
Resolution: Not A Defect

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 9:57:06 AM10/22/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 10:12:02 AM10/22/19
to jenkinsc...@googlegroups.com

I link to JENKINS-59844 because it is the issue that discovers this one. A NodeProperty implementer was calling the ProcessBuilder#_start method (JDK) with an empty command, therefore throwing an _IndexOutOfBoundExceptions and hanging the queue. Every job reviewed in the Queue#maintain method after this event is not managed because the method ends abruptly.

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 10:13:02 AM10/22/19
to jenkinsc...@googlegroups.com
Ramon Leon updated an issue
Change By: Ramon Leon
Comment: I link to JENKINS-59844 because it is the issue that discovers this one. A _NodeProperty_ implementer was calling the _ProcessBuilder#_start method (JDK) with an empty command, therefore throwing an _IndexOutOfBoundExceptions_ and hanging the queue. Every job reviewed in the _Queue#maintain_ method after this event is not managed because the method ends abruptly.

ealvarez@cloudbees.com (JIRA)

unread,
Oct 22, 2019, 12:27:03 PM10/22/19
to jenkinsc...@googlegroups.com
Esther Álvarez Feijoo commented on Improvement JENKINS-59844
 
Re: Process Launcher shouldn't throw ArrayIndexOutOfBoundException on empty command

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.

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 22, 2019, 12:40:02 PM10/22/19
to jenkinsc...@googlegroups.com

ealvarez@cloudbees.com (JIRA)

unread,
Oct 24, 2019, 11:36:05 AM10/24/19
to jenkinsc...@googlegroups.com

After talking with Ramon Leon, 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

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 24, 2019, 2:33:02 PM10/24/19
to jenkinsc...@googlegroups.com

manuelramonleonjimenez@gmail.com (JIRA)

unread,
Oct 24, 2019, 2:34:04 PM10/24/19
to jenkinsc...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages