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

Don't catch a generic Exception following a multi-catch statement #742

Merged
merged 2 commits into from
Apr 28, 2016

Conversation

danieldickison
Copy link
Contributor

Currently a multi-catch statement like:

catch (A | B e) {}

is translated to three objc @catch clauses:

@catch (A *e) {}
@catch (B *e) {}
@catch (JavaLangRuntimeException *e) {}

The last @catch clause seems to be the closest common ancestor of A and B, but from what I understand, this doesn't match the semantics of the Java multi-catch syntax. In fact, if the multi-catch is followed by a catch (C e) {}, where C also inherits RuntimeException, the translated @catch (C *e) clause is never reached because it is shadowed by the extraneous @catch clause.

This pull request changes the translation to omit the extra @catch clause after a multi-catch. Please review because I can't help but think that the extra @catch clause was previously being generated intentionally.

@@ -132,6 +132,20 @@ public void testCatchTranslation() throws IOException {
assertEquals("@try {\n;\n}\n @catch (JavaLangException *e) {\n}", result);
}

public void testMultiCatchTranslation() throws IOException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you instead merge this into testMultiCatch() below, and use assertTranslatedLines to verify the translation.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call, I had overlooked testMutiCatch() earlier. Updated the pull request but used assertNotInTranslation() instead of assertTranslatedLines() for the sake of brevity. Do you think that's sufficient?

@kstanger
Copy link
Collaborator

The Travis build timed out, but at least got past j2objc compilation and translation of jre sources, so I'll pull this anyways.

@kstanger kstanger merged commit 4c9324c into google:master Apr 28, 2016
@danieldickison
Copy link
Contributor Author

Thanks for the quick response and merge!

@danieldickison danieldickison deleted the multicatch branch April 28, 2016 18:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants