6864382: NPE in the rich formatter when processing an unattributed type-variable

Thu, 30 Jul 2009 10:30:24 +0100

author
mcimadamore
date
Thu, 30 Jul 2009 10:30:24 +0100
changeset 343
dd5c51734ad9
parent 342
b1e027181dd4
child 344
6d0add6ad778

6864382: NPE in the rich formatter when processing an unattributed type-variable
Summary: Unattributed type variable should not be accessed by the rich formatter when emitting where clauses
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/6864382/T6864382.java file | annotate | diff | comparison | revisions
test/tools/javac/Diagnostics/6864382/T6864382.out file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Thu Jul 30 10:30:10 2009 +0100
     1.2 +++ b/src/share/classes/com/sun/tools/javac/util/RichDiagnosticFormatter.java	Thu Jul 30 10:30:24 2009 +0100
     1.3 @@ -524,10 +524,16 @@
     1.4          @Override
     1.5          public Void visitTypeVar(TypeVar t, Void ignored) {
     1.6              if (indexOf(t, WhereClauseKind.TYPEVAR) == -1) {
     1.7 +                //access the bound type and skip error types
     1.8                  Type bound = t.bound;
     1.9                  while ((bound instanceof ErrorType))
    1.10                      bound = ((ErrorType)bound).getOriginalType();
    1.11 -                List<Type> bounds  = types.getBounds(t);
    1.12 +                //retrieve the bound list - if the type variable
    1.13 +                //has not been attributed the bound is not set
    1.14 +                List<Type> bounds = bound != null ?
    1.15 +                    types.getBounds(t) :
    1.16 +                    List.<Type>nil();
    1.17 +
    1.18                  nameSimplifier.addUsage(t.tsym);
    1.19  
    1.20                  boolean boundErroneous = bounds.head == null ||
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/Diagnostics/6864382/T6864382.java	Thu Jul 30 10:30:24 2009 +0100
     2.3 @@ -0,0 +1,32 @@
     2.4 +/*
     2.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    2.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    2.24 + * have any questions.
    2.25 + */
    2.26 +
    2.27 +/**
    2.28 + * @test
    2.29 + * @bug     6864382
    2.30 + * @summary NullPointerException when compiling a negative java source
    2.31 + * @author  mcimadamore
    2.32 + * @compile/fail/ref=T6864382.out -XDrawDiagnostics  T6864382.java
    2.33 + */
    2.34 +
    2.35 +class T6864382<T> extends T {}
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/tools/javac/Diagnostics/6864382/T6864382.out	Thu Jul 30 10:30:24 2009 +0100
     3.3 @@ -0,0 +1,2 @@
     3.4 +T6864382.java:32:27: compiler.err.type.found.req: (compiler.misc.type.parameter: T), (compiler.misc.type.req.class)
     3.5 +1 error

mercurial