- 
    Bug 
- 
    Resolution: Fixed
- 
     P4 P4
- 
    None
- 
    None
- 
        b94
                    The way we generate code, the symbol for ":e" internal exception variable has type ECMAException, when it should have Throwable. Curiously, this passes the verifier and doesn't cause problems, but it's obviously wrong. This program works:
try {
new java.io.FileInputStream("no-such-file");
} catch(e) {
print(e.class)
e.printStackTrace()
}
But the generated bytecode for the catch block is:
FRAME FULL [jdk/nashorn/internal/runtime/ScriptFunction java/lang/Object jdk/nashorn/internal/runtime/ScriptObject java/lang/Object] [java/lang/Throwable]
ASTORE 4
L5
ALOAD 4
DUP
INSTANCEOF jdk/nashorn/internal/runtime/ECMAException
IFEQ L6
CHECKCAST jdk/nashorn/internal/runtime/ECMAException
GETFIELD jdk/nashorn/internal/runtime/ECMAException.thrown : Ljava/lang/Object;
...
LOCALVARIABLE :e Ljdk/nashorn/internal/runtime/ECMAException; L0 L4 4
meaning, we can catch any Throwable and then set it into a lvar typed as ECMAException.
":e" should obviously be typed as Throwable.
            
try {
new java.io.FileInputStream("no-such-file");
} catch(e) {
print(e.class)
e.printStackTrace()
}
But the generated bytecode for the catch block is:
FRAME FULL [jdk/nashorn/internal/runtime/ScriptFunction java/lang/Object jdk/nashorn/internal/runtime/ScriptObject java/lang/Object] [java/lang/Throwable]
ASTORE 4
L5
ALOAD 4
DUP
INSTANCEOF jdk/nashorn/internal/runtime/ECMAException
IFEQ L6
CHECKCAST jdk/nashorn/internal/runtime/ECMAException
GETFIELD jdk/nashorn/internal/runtime/ECMAException.thrown : Ljava/lang/Object;
...
LOCALVARIABLE :e Ljdk/nashorn/internal/runtime/ECMAException; L0 L4 4
meaning, we can catch any Throwable and then set it into a lvar typed as ECMAException.
":e" should obviously be typed as Throwable.