From 3755f90fef79983e730515077451a87302f1de7b Mon Sep 17 00:00:00 2001 From: Hubert Plociniczak Date: Fri, 15 Mar 2024 11:44:30 +0100 Subject: [PATCH] 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. --- .../java/org/enso/interpreter/service/ExecutionService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/service/ExecutionService.java b/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/service/ExecutionService.java index 042d93c8cc5..bf30007acf9 100644 --- a/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/service/ExecutionService.java +++ b/engine/runtime-instrument-common/src/main/java/org/enso/interpreter/service/ExecutionService.java @@ -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;