This is about differences in the general behavior of DocTrees.getElement
compared to Elements.getTypeElement, with respect to primitive types and arrays.
(It is NOT about the different functionality arising from the potentially different scope context implied by the parameters.)
DocTrees.getElement returns the javac "internal" Symbols for primitive types, and the component type for arrays. Elements.getTypeElement returns `null` for both of these. More explicitly, if you use `Types.getPrimitiveType(...).asElement()` the implementation explicitly filters out certain symbols, like the symbols for primitive types, and returns null instead.
Returning the javac internal symbol (from DocTrees.getElement) is dangerous because it exposes other "internal" symbols, like `rootPackage` which is a special internal package that itself has no parent (owner).
Returning the base component of arrays from `DocTrees.getElement` seems over-zealous and inappropriate, even if it is or has been necessary to support javadoc. Those contexts in javadoc that allow types (e.g. @serialField) should use `DocTrees.getType` instead of `DocTrees.getElement`.
compared to Elements.getTypeElement, with respect to primitive types and arrays.
(It is NOT about the different functionality arising from the potentially different scope context implied by the parameters.)
DocTrees.getElement returns the javac "internal" Symbols for primitive types, and the component type for arrays. Elements.getTypeElement returns `null` for both of these. More explicitly, if you use `Types.getPrimitiveType(...).asElement()` the implementation explicitly filters out certain symbols, like the symbols for primitive types, and returns null instead.
Returning the javac internal symbol (from DocTrees.getElement) is dangerous because it exposes other "internal" symbols, like `rootPackage` which is a special internal package that itself has no parent (owner).
Returning the base component of arrays from `DocTrees.getElement` seems over-zealous and inappropriate, even if it is or has been necessary to support javadoc. Those contexts in javadoc that allow types (e.g. @serialField) should use `DocTrees.getType` instead of `DocTrees.getElement`.
- relates to
-
JDK-8284193 DocTrees.getElement(DocTreePath) returns javac-internal Symbols
-
- Open
-