RFR: JDK-8062359: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
Jan Lahoda
jan.lahoda at oracle.com
Tue Nov 18 13:36:12 UTC 2014
Hi,
Is there a chance to get the actual javac options+list of files (in the
given order) that get passed to javac when the NPE happens? Might be
possible to reproduce with that?
Thanks,
Jan
On 18.11.2014 11:41, Joel Borggrén-Franck wrote:
> Hi,
>
> Here is a proposed fix for [1]: javac Attr crashes with NPE in TypeAnnotationsValidator visitNewClass
>
> This is for 9 but I will propose an identical backport to 8u as well. Patch is very small:
>
> diff -r c2339b4749af src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java
> --- a/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Mon Nov 17 23:11:05 2014 -0800
> +++ b/src/jdk.compiler/share/classes/com/sun/tools/javac/comp/Attr.java Tue Nov 18 10:23:57 2014 +0100
> @@ -4486,14 +4486,16 @@
> super.visitTypeTest(tree);
> }
> public void visitNewClass(JCNewClass tree) {
> - if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
> - checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
> - tree.clazz.type.tsym);
> - }
> - if (tree.def != null) {
> - checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym);
> - }
> - if (tree.clazz.type != null) {
> + if (tree.clazz != null && tree.clazz.type != null) {
> + if (tree.clazz.hasTag(ANNOTATED_TYPE)) {
> + checkForDeclarationAnnotations(((JCAnnotatedType) tree.clazz).annotations,
> + tree.clazz.type.tsym);
> + }
> +
> + if (tree.def != null) {
> + checkForDeclarationAnnotations(tree.def.mods.annotations, tree.clazz.type.tsym);
> + }
> +
> validateAnnotatedType(tree.clazz, tree.clazz.type);
> }
> super.visitNewClass(tree);
>
> — 8< —
>
> I can’t reproduce the issue, but as the initial report (CC:ed) wrote, and as nearby methods hint at, tree.clazz.type can be null which may NPE in the second if clause guarded by tree.def != null.
>
> My proposed fix is to add guards similar to visitTypeCast or visitTypeTest. There is no test since I can’t reproduce this, but the existing langtools regression tests pass, and I have run a jcov report that at least shows the method has good coverage by the existing tests.
>
> If anyone is able to reproduce this I would be glad if you tried out the patch.
>
> thanks in advance
>
> cheers
> /Joel
>
> [1] https://bugs.openjdk.java.net/browse/JDK-8062359
>
More information about the compiler-dev
mailing list