In JavaCompiler, line 1308, 1993, if there are task listeners registered, they will be called with an ANALYZE TaskEvent.
For most files, this is good and works well.
But, for package-info and module-info files, the type element is set to a shared anonymous class, syms.predefClass. Since there is no other way in a task listener to get at the module element or module-info class, or the package element or package-info class, it would be better if the type element in the TaskEvent object was set to the symbol for `module-info` or `package-info` as appropriate.
I've attached a patch for a possible fix, which works by detecting the type of compilation unit. There may be better ways to fix this, perhaps by modifying the info in the env in some way. But the patch is simple and localized, so relatively low risk and low cost.
But by itself the patch is not enough, and uncovers a separate bug, for which I do not have a proposed fix. If the patch is applied, and a task listener calls `Elements.getModuleOf` or `Elements.getPackageOf` on the type element for module-info, the compiler crashes with NPE, because the call of sym.packge() in JavacElements.getModuleOf:459 returns null. The equivalent call in `getPackageOf` crashes with NPE for the same reason.
I believe the Elements.getModuleOf and Elements.getPackageOf calls on the type element for package-info work OK, but that should be verified.
For most files, this is good and works well.
But, for package-info and module-info files, the type element is set to a shared anonymous class, syms.predefClass. Since there is no other way in a task listener to get at the module element or module-info class, or the package element or package-info class, it would be better if the type element in the TaskEvent object was set to the symbol for `module-info` or `package-info` as appropriate.
I've attached a patch for a possible fix, which works by detecting the type of compilation unit. There may be better ways to fix this, perhaps by modifying the info in the env in some way. But the patch is simple and localized, so relatively low risk and low cost.
But by itself the patch is not enough, and uncovers a separate bug, for which I do not have a proposed fix. If the patch is applied, and a task listener calls `Elements.getModuleOf` or `Elements.getPackageOf` on the type element for module-info, the compiler crashes with NPE, because the call of sym.packge() in JavacElements.getModuleOf:459 returns null. The equivalent call in `getPackageOf` crashes with NPE for the same reason.
I believe the Elements.getModuleOf and Elements.getPackageOf calls on the type element for package-info work OK, but that should be verified.
- is cloned by
-
JDK-8283714 REDO - Unexpected TypeElement in ANALYZE TaskEvent
-
- Resolved
-
- relates to
-
JDK-8283713 [BACKOUT] Unexpected TypeElement in ANALYZE TaskEvent
-
- Resolved
-
-
JDK-8284030 Standard Doclet should not attempt to link to primitive types
-
- Resolved
-