Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bugs in Painless SCatch node #45880

Merged
merged 1 commit into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,9 @@ public SCatch(Location location, String type, String name, SBlock block) {

@Override
void storeSettings(CompilerSettings settings) {
block.storeSettings(settings);
if (block != null) {
block.storeSettings(settings);
}
}

@Override
Expand Down Expand Up @@ -115,7 +117,7 @@ void write(MethodWriter writer, Globals globals) {

writer.visitTryCatchBlock(begin, end, jump, MethodWriter.getType(variable.clazz).getInternalName());

if (exception != null && !block.allEscape) {
if (exception != null && (block == null || !block.allEscape)) {
writer.goTo(exception);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,4 +55,47 @@ public void testNoCatch() {
});
assertEquals("test", exception.getMessage());
}

public void testNoCatchBlock() {
assertEquals(0, exec("try { return Integer.parseInt('f') } catch (NumberFormatException nfe) {} return 0;"));

assertEquals(0, exec("try { return Integer.parseInt('f') } " +
"catch (NumberFormatException nfe) {}" +
"catch (Exception e) {}" +
" return 0;"));

assertEquals(0, exec("try { throw new IllegalArgumentException('test') } " +
"catch (NumberFormatException nfe) {}" +
"catch (Exception e) {}" +
" return 0;"));

assertEquals(0, exec("try { throw new IllegalArgumentException('test') } " +
"catch (NumberFormatException nfe) {}" +
"catch (IllegalArgumentException iae) {}" +
"catch (Exception e) {}" +
" return 0;"));
}

public void testMultiCatch() {
assertEquals(1, exec(
"try { return Integer.parseInt('f') } " +
"catch (NumberFormatException nfe) {return 1;} " +
"catch (ArrayIndexOutOfBoundsException aioobe) {return 2;} " +
"catch (Exception e) {return 3;}"
));

assertEquals(2, exec(
"try { return new int[] {}[0] } " +
"catch (NumberFormatException nfe) {return 1;} " +
"catch (ArrayIndexOutOfBoundsException aioobe) {return 2;} " +
"catch (Exception e) {return 3;}"
));

assertEquals(3, exec(
"try { throw new IllegalArgumentException('test'); } " +
"catch (NumberFormatException nfe) {return 1;} " +
"catch (ArrayIndexOutOfBoundsException aioobe) {return 2;} " +
"catch (Exception e) {return 3;}"
));
}
}