From fe1aaa815421a0d0aea129dc136a3a14fda3ba03 Mon Sep 17 00:00:00 2001 From: Maurizio Cimadamore Date: Thu, 30 Jul 2009 10:30:24 +0100 Subject: [PATCH] 6864382: NPE in the rich formatter when processing an unattributed type-variable Unattributed type variable should not be accessed by the rich formatter when emitting where clauses Reviewed-by: jjg --- .../javac/util/RichDiagnosticFormatter.java | 8 ++++- .../javac/Diagnostics/6864382/T6864382.java | 32 +++++++++++++++++++ .../javac/Diagnostics/6864382/T6864382.out | 2 ++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 langtools/test/tools/javac/Diagnostics/6864382/T6864382.java create mode 100644 langtools/test/tools/javac/Diagnostics/6864382/T6864382.out diff --git a/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java b/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java index 58812a781d7..2275ba935b4 100644 --- a/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java +++ b/langtools/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java @@ -524,10 +524,16 @@ public class RichDiagnosticFormatter extends @Override public Void visitTypeVar(TypeVar t, Void ignored) { if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) { + //access the bound type and skip error types Type bound = t.bound; while ((bound instanceof ErrorType)) bound = ((ErrorType)bound).getOriginalType(); - List bounds = types.getBounds(t); + //retrieve the bound list - if the type variable + //has not been attributed the bound is not set + List bounds = bound != null ? + types.getBounds(t) : + List.nil(); + nameSimplifier.addUsage(t.tsym); boolean boundErroneous = bounds.head == null || diff --git a/langtools/test/tools/javac/Diagnostics/6864382/T6864382.java b/langtools/test/tools/javac/Diagnostics/6864382/T6864382.java new file mode 100644 index 00000000000..f6ab5d891a1 --- /dev/null +++ b/langtools/test/tools/javac/Diagnostics/6864382/T6864382.java @@ -0,0 +1,32 @@ +/* + * Copyright 2009 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * This code is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License + * version 2 for more details (a copy is included in the LICENSE file that + * accompanied this code). + * + * You should have received a copy of the GNU General Public License version + * 2 along with this work; if not, write to the Free Software Foundation, + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. + * + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/** + * @test + * @bug 6864382 + * @summary NullPointerException when compiling a negative java source + * @author mcimadamore + * @compile/fail/ref=T6864382.out -XDrawDiagnostics T6864382.java + */ + +class T6864382 extends T {} diff --git a/langtools/test/tools/javac/Diagnostics/6864382/T6864382.out b/langtools/test/tools/javac/Diagnostics/6864382/T6864382.out new file mode 100644 index 00000000000..40013de7081 --- /dev/null +++ b/langtools/test/tools/javac/Diagnostics/6864382/T6864382.out @@ -0,0 +1,2 @@ +T6864382.java:32:27: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class) +1 error