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 1 10:57:40 PDT 2013
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