Possible oversight in JLS8 Section 16.2.15

Hiram Hunt hiramhunt at verizon.net
Wed Jun 15 13:48:11 UTC 2022


Hello,

The last bulleted item of JLS8 Section 16.2.15
says

• V is definitely unassigned before the finally
   block iff all of the following are true:

This is followed by seven items marked by dashes.
The first of the seven items takes care of normal
completion of the try block and the seventh item
takes care of normal completion of any catch blocks.
The five items in between take care of some (all,
I hope) cases of abrupt completion of the try
block, but I don't see anything that takes care
of abrupt completion of any catch blocks.

Although javac (reasonably) rejects the following
code, I cannot justify it from the definite
assignment description in the JLS because the
return is in a catch block, not the try block:


class DefAssign {
     final int blank;
     public DefAssign() {
         try {
             throw new Exception("Exception");
         } catch (Exception e) {
             blank = 1;
             return;
         } finally {
             blank = 2;  // Expected, but
                         // undocumented(?), javac error.
         }
     }
}

-- Hiram Hunt (hiramhunt at verizon.net)




More information about the jls-jvms-spec-comments mailing list