RFR: 8271254: javac generates unreachable code when using empty semicolon statement

Vicente Romero vromero at openjdk.java.net
Mon Sep 13 17:21:53 UTC 2021

On Mon, 13 Sep 2021 15:26:38 GMT, Guoxiong Li <gli at openjdk.org> wrote:

> Hi all,
> The method `Gen#genTry` is used by `visitTry` and `visitSynchronized`, but `genTry` can't identify who is invoking it so that it can't solve the concrete issues about try statement or synchronized statement separately. This patch adds a new parameter `actualTry` to identify the concrete situation( try or synchronized) and fixes this issue about using empty skip statement in the try statement body. And some related test cases are added.
> Thanks for taking the time to review.
> Best Regards,
> -- Guoxiong

Changes requested by vromero (Reviewer).

src/jdk.compiler/share/classes/com/sun/tools/javac/jvm/Gen.java line 1517:

> 1515:          *  @param actualTry Identify try or synchronized statement, true for try and false for synchronized.
> 1516:          */
> 1517:         void genTry(JCTree body, List<JCCatch> catchers, Env<GenContext> env, boolean actualTry) {

I don't think you really need an additional argument, I think that you can check for the tree at the `env` argument and you should be able to find out if this method is being invoked from a `try` or not. Kind of:

boolean actualTry = env.tree.hasTag(TRY);


PR: https://git.openjdk.java.net/jdk/pull/5495

More information about the compiler-dev mailing list