6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.

Thu, 02 Sep 2010 23:10:05 +0530

author
sundar
date
Thu, 02 Sep 2010 23:10:05 +0530
changeset 666
f37253c9e082
parent 665
d3ead6731a91
child 667
3ff3f20471b4

6458749: TypeParameterElement.getEnclosedElements throws NPE within javac.
Reviewed-by: jjg

src/share/classes/com/sun/tools/javac/code/Symbol.java file | annotate | diff | comparison | revisions
test/tools/javac/T6458749.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/classes/com/sun/tools/javac/code/Symbol.java	Wed Sep 01 03:19:16 2010 -0700
     1.2 +++ b/src/share/classes/com/sun/tools/javac/code/Symbol.java	Thu Sep 02 23:10:05 2010 +0530
     1.3 @@ -579,6 +579,9 @@
     1.4  
     1.5          public java.util.List<Symbol> getEnclosedElements() {
     1.6              List<Symbol> list = List.nil();
     1.7 +            if (kind == TYP && type.tag == TYPEVAR) {
     1.8 +                return list;
     1.9 +            }
    1.10              for (Scope.Entry e = members().elems; e != null; e = e.sibling) {
    1.11                  if (e.sym != null && (e.sym.flags() & SYNTHETIC) == 0 && e.sym.owner == this)
    1.12                      list = list.prepend(e.sym);
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/tools/javac/T6458749.java	Thu Sep 02 23:10:05 2010 +0530
     2.3 @@ -0,0 +1,62 @@
     2.4 +/*
     2.5 + * Copyright (c) 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +/*
    2.28 + * @test
    2.29 + * @bug 6458749
    2.30 + * @summary  TypeParameterElement.getEnclosedElements() throws NPE within javac
    2.31 + * @build T6458749
    2.32 + * @compile -processor T6458749 -proc:only T6458749.java
    2.33 + */
    2.34 +
    2.35 +import java.util.Set;
    2.36 +import javax.annotation.processing.*;
    2.37 +import javax.lang.model.element.*;
    2.38 +import javax.lang.model.util.ElementFilter;
    2.39 +import javax.lang.model.SourceVersion;
    2.40 +
    2.41 +@SupportedAnnotationTypes("*")
    2.42 +public class T6458749<T> extends AbstractProcessor {
    2.43 +    public boolean process(Set<? extends TypeElement> tes, RoundEnvironment renv) {
    2.44 +        if (!renv.processingOver()) {
    2.45 +            for(TypeElement e : ElementFilter.typesIn(renv.getRootElements())) {
    2.46 +                System.out.printf("Element %s:%n", e.toString());
    2.47 +                try {
    2.48 +                    for (TypeParameterElement tp : e.getTypeParameters()) {
    2.49 +                        System.out.printf("Type param %s", tp.toString());
    2.50 +                        if (! tp.getEnclosedElements().isEmpty()) {
    2.51 +                            throw new AssertionError("TypeParameterElement.getEnclosedElements() should return empty list");
    2.52 +                        }
    2.53 +                    }
    2.54 +                } catch (NullPointerException npe) {
    2.55 +                    throw new AssertionError("NPE from TypeParameterElement.getEnclosedElements()", npe);
    2.56 +                }
    2.57 +            }
    2.58 +        }
    2.59 +        return true;
    2.60 +    }
    2.61 +
    2.62 +    public SourceVersion getSupportedSourceVersion() {
    2.63 +        return SourceVersion.latest();
    2.64 +    }
    2.65 +}

mercurial