try{} catch(@ex) {} throws a Java IndexOutOfBoundsException in compile time
Pieter12345 opened this issue ยท 1 comments
Code:
try{} catch(@ex) {}
Stacktrace:
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
at java.base/jdk.internal.util.Preconditions.outOfBounds(Preconditions.java:64)
at java.base/jdk.internal.util.Preconditions.outOfBoundsCheckIndex(Preconditions.java:70)
at java.base/jdk.internal.util.Preconditions.checkIndex(Preconditions.java:248)
at java.base/java.util.Objects.checkIndex(Objects.java:372)
at java.base/java.util.ArrayList.get(ArrayList.java:459)
at com.laytonsmith.core.ParseTree.getChildAt(ParseTree.java:170)
at com.laytonsmith.core.functions.Exceptions$complex_try.optimizeDynamic(Exceptions.java:602)
at com.laytonsmith.core.MethodScriptCompiler.optimize(MethodScriptCompiler.java:2467)
at com.laytonsmith.core.MethodScriptCompiler.compile(MethodScriptCompiler.java:1847)
at com.laytonsmith.tools.Interpreter.execute(Interpreter.java:782)
at com.laytonsmith.tools.Interpreter.execute(Interpreter.java:717)
at com.laytonsmith.tools.Interpreter.textLine(Interpreter.java:481)
at com.laytonsmith.tools.Interpreter.<init>(Interpreter.java:318)
at com.laytonsmith.tools.Interpreter.<init>(Interpreter.java:239)
at com.laytonsmith.core.Main$InterpreterMode.execute(Main.java:541)
at com.laytonsmith.core.Main.main(Main.java:313)
CommandHelper build #4029.
This should be fairly straightforward to fix, which I'll do when this bug is still open when I have some free time behind my main PC. Note that this should give a syntax error, as the exception type is missing.
When fixing this, the complex_try.optimizeDynamic()
method should be checked for robustness against invalid input. Code
try{} catch(Exception @ex 1) {}
Results in:
Exception in thread "main" java.lang.ClassCastException: class com.laytonsmith.core.constructs.CFunction cannot be cast to class com.laytonsmith.core.constructs.CClassType (com.laytonsmith.core.constructs.CFunction and com.laytonsmith.core.constructs.CClassType are in unnamed module of loader 'app')
at com.laytonsmith.core.functions.Exceptions$complex_try.optimizeDynamic(Exceptions.java:606)
at com.laytonsmith.core.MethodScriptCompiler.optimize(MethodScriptCompiler.java:2467)
at com.laytonsmith.core.MethodScriptCompiler.compile(MethodScriptCompiler.java:1847)
at com.laytonsmith.tools.Interpreter.execute(Interpreter.java:782)
at com.laytonsmith.tools.Interpreter.execute(Interpreter.java:717)
at com.laytonsmith.tools.Interpreter.textLine(Interpreter.java:481)
at com.laytonsmith.tools.Interpreter.<init>(Interpreter.java:318)
at com.laytonsmith.tools.Interpreter.<init>(Interpreter.java:239)
at com.laytonsmith.core.Main$InterpreterMode.execute(Main.java:541)
at com.laytonsmith.core.Main.main(Main.java:313)
It should also be checked whether this method actually is an optimization, or rather a parser rewrite step, in which case the rewrite code should be moved to postParseRewrite()
.