Avoid ArrayIndexOutOfBoundsException with no args (#9393)

The `null` check creates a new Array but always assumed a non-empty one which may lead to
```
java.lang.ArrayIndexOutOfBoundsException: Index 0 out of bounds for length 0
at org.enso.runtime/org.enso.interpreter.service.ExecutionService$FunctionPointer.collectNotAppliedArguments(ExecutionService.java:778)
at org.enso.runtime/org.enso.interpreter.instrument.job.ProgramExecutionSupport$.sendExpressionUpdate(ProgramExecutionSupport.scala:430)
at org.enso.runtime/org.enso.interpreter.instrument.job.ProgramExecutionSupport$.$anonfun$executeProgram$3(ProgramExecutionSupport.scala:81)
at org.enso.runtime/org.enso.interpreter.service.ExecutionCallbacks.callOnComputedCallback(ExecutionCallbacks.java:146)
at
org.enso.runtime/org.enso.interpreter.service.ExecutionCallbacks.updateCachedResult(ExecutionCallbacks.java:117
...
```
Added a guard to prevent the exception. The flag will be useless anyway as we won't enter the for-loop in this case.

Appears to be introduced via #8743. Discovered while debugging #9389.
This commit is contained in:
Hubert Plociniczak 2024-03-15 11:44:30 +01:00 committed by GitHub
parent 8d9c25cdda
commit 3755f90fef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -775,7 +775,7 @@ public final class ExecutionService {
if (preAppliedArguments == null) {
preAppliedArguments = new Object[functionSchema.getArgumentsCount()];
}
boolean isStatic = preAppliedArguments[0] instanceof Type;
boolean isStatic = preAppliedArguments.length == 0 || preAppliedArguments[0] instanceof Type;
int selfArgumentPosition = isStatic ? -1 : 0;
int[] notAppliedArguments = new int[functionSchema.getArgumentsCount()];
int notAppliedArgumentsLength = 0;