about bug: 8020216: Compile time error isn't shown when final class variable is not assigned

Vicente-Arturo Romero-Zaldivar vicente.romero at oracle.com
Thu Aug 8 02:57:00 PDT 2013


Well this code sample was to show what problems a "fix" to bug 8020216 
may imply. If you check the corresponding bug entry [1], there is 
another similar case and I'm writing you because there you added a 
comment saying that it should be a compiler error. Probably that case is 
different from this one. For me this is not an issue.

Vicente

[1] https://jbs.oracle.com/bugs/browse/JDK-8020216

PD. the comments I'm referring to are not present in 
http://bugs.sun.com/bugdatabase


On 08/08/13 01:59, Alex Buckley wrote:
> Each of the three final instance variables is not definitely assigned 
> after the if-then-else, but JLS 16 only requires a compile-time error 
> when such a variable is accessed. There's no access in the code below, 
> so why is an error being given?
>
> Alex
>
> On 8/1/2013 10:57 AM, Vicente-Arturo Romero-Zaldivar wrote:
>> Hi Alex,
>>
>> Regarding the mentioned bug entry, I have a patch that solves the issue
>> but then I have the following example taken from javac code:
>>
>> private final TreePath treePath;
>> private final DocCommentTree docComment;
>> private final DocTreePath parent;
>>
>>       public DocTreePath(DocTreePath p, DocTree t) {
>>           if (t.getKind() == DocTree.Kind.DOC_COMMENT) {
>>               throw new IllegalArgumentException("Use
>> DocTreePath(TreePath, DocCommentTree) to construct DocTreePath for a
>> DocCommentTree.");
>>           } else {
>>               treePath = p.treePath;
>>               docComment = p.docComment;
>>               parent = p;
>>           }
>>           leaf = t;
>>       }
>>
>> with the patch javac says:
>>
>> error: variable treePath might not have been initialized
>> error: variable docComment might not have been initialized
>> error: variable parent might not have been initialized
>>
>> so this means that whenever we have such a code we will have to do:
>>
>>           if (t.getKind() == DocTree.Kind.DOC_COMMENT) {
>>               treePath = null;
>>               docComment = null;
>>               parent = null;
>>               throw new IllegalArgumentException("Use
>> DocTreePath(TreePath, DocCommentTree) to construct DocTreePath for a
>> DocCommentTree.");
>>           } else {
>>
>> another option is to set the fields to null at the end of the method.
>>
>> Is this what we want? I think the current state of flow analysis is
>> preferable but I wanted to double check before going on.
>>
>> Thanks,
>> Vicente



More information about the compiler-dev mailing list