Mon, 14 Mar 2011 11:33:33 -0700
7026414: Types.asElement() returns null for ErrorType
Reviewed-by: darcy
1.1 --- a/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Fri Mar 11 15:39:51 2011 -0800 1.2 +++ b/src/share/classes/com/sun/tools/javac/model/JavacTypes.java Mon Mar 14 11:33:33 2011 -0700 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2005, 2011, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -73,9 +73,14 @@ 1.11 1.12 public Element asElement(TypeMirror t) { 1.13 Type type = cast(Type.class, t); 1.14 - if (type.tag != TypeTags.CLASS && type.tag != TypeTags.TYPEVAR) 1.15 - return null; 1.16 - return type.asElement(); 1.17 + switch (type.tag) { 1.18 + case TypeTags.CLASS: 1.19 + case TypeTags.ERROR: 1.20 + case TypeTags.TYPEVAR: 1.21 + return type.asElement(); 1.22 + default: 1.23 + return null; 1.24 + } 1.25 } 1.26 1.27 public boolean isSameType(TypeMirror t1, TypeMirror t2) {
2.1 --- a/test/tools/javac/api/6557752/T6557752.java Fri Mar 11 15:39:51 2011 -0800 2.2 +++ b/test/tools/javac/api/6557752/T6557752.java Mon Mar 14 11:33:33 2011 -0700 2.3 @@ -118,7 +118,8 @@ 2.4 2.5 Types types = task.getTypes(); 2.6 2.7 - if (types.asElement(trees.getOriginalType((ErrorType)typeMirror)) != null) { 2.8 + str1 = types.asElement(trees.getOriginalType((ErrorType)typeMirror)).toString(); 2.9 + if (!str1.equals("FooBar")) { 2.10 throw new AssertionError("Types.asElement() error!"); 2.11 } 2.12 foundError = true;
3.1 --- a/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Fri Mar 11 15:39:51 2011 -0800 3.2 +++ b/test/tools/javac/processing/model/element/TestMissingElement/TestMissingElement.java Mon Mar 14 11:33:33 2011 -0700 3.3 @@ -24,7 +24,7 @@ 3.4 3.5 /* 3.6 * @test 3.7 - * @bug 6639645 3.8 + * @bug 6639645 7026414 3.9 * @summary Modeling type implementing missing interfaces 3.10 * @library ../../../../lib 3.11 * @build JavacTestingAbstractProcessor TestMissingElement 3.12 @@ -112,6 +112,7 @@ 3.13 3.14 @Override 3.15 public String visitDeclared(DeclaredType t, Void ignore) { 3.16 + checkEqual(t.asElement(), types.asElement(t)); 3.17 String s = asString(t.asElement()); 3.18 List<? extends TypeMirror> args = t.getTypeArguments(); 3.19 if (!args.isEmpty()) 3.20 @@ -179,6 +180,13 @@ 3.21 return (e != null && e.getKind() == ElementKind.PACKAGE 3.22 && ((PackageElement) e).isUnnamed()); 3.23 } 3.24 + 3.25 + void checkEqual(Element e1, Element e2) { 3.26 + if (e1 != e2) { 3.27 + throw new AssertionError("elements not equal as expected: " 3.28 + + e1 + ", " + e2); 3.29 + } 3.30 + } 3.31 } 3.32 3.33