Skip to content

Commit

Permalink
Avoid ArrayIndexOutOfBoundsException with no args (#9393)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hubertp committed Mar 15, 2024
1 parent 8d9c25c commit 3755f90
Showing 1 changed file with 1 addition and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -775,7 +775,7 @@ public static int[] collectNotAppliedArguments(Function function) {
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;
Expand Down

0 comments on commit 3755f90

Please sign in to comment.