Fri, 22 Oct 2010 14:04:33 -0700
6993301: catch parameters do not have correct kind (i.e. ElementKind.EXCEPTION_PARAMETER)
Reviewed-by: mcimadamore
src/share/classes/com/sun/tools/javac/comp/Attr.java | file | annotate | diff | comparison | revisions | |
test/tools/javac/T6993301.java | file | annotate | diff | comparison | revisions |
1.1 --- a/src/share/classes/com/sun/tools/javac/comp/Attr.java Tue Oct 19 15:02:48 2010 -0700 1.2 +++ b/src/share/classes/com/sun/tools/javac/comp/Attr.java Fri Oct 22 14:04:33 2010 -0700 1.3 @@ -1055,7 +1055,7 @@ 1.4 } 1.5 c.param.sym.flags_field = c.param.sym.flags() | DISJOINT; 1.6 } 1.7 - if (c.param.type.tsym.kind == Kinds.VAR) { 1.8 + if (c.param.sym.kind == Kinds.VAR) { 1.9 c.param.sym.setData(ElementKind.EXCEPTION_PARAMETER); 1.10 } 1.11 chk.checkType(c.param.vartype.pos(),
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/test/tools/javac/T6993301.java Fri Oct 22 14:04:33 2010 -0700 2.3 @@ -0,0 +1,105 @@ 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 6993301 2.30 + * @summary catch parameters do not have correct kind (i.e. ElementKind.EXCEPTION_PARAMETER) 2.31 + */ 2.32 + 2.33 +import com.sun.source.tree.CompilationUnitTree; 2.34 +import com.sun.source.tree.IdentifierTree; 2.35 +import com.sun.source.tree.VariableTree; 2.36 +import com.sun.source.util.TreePathScanner; 2.37 +import com.sun.source.util.Trees; 2.38 +import com.sun.tools.javac.api.JavacTaskImpl; 2.39 +import java.io.IOException; 2.40 +import java.net.URI; 2.41 +import java.util.Arrays; 2.42 +import javax.lang.model.element.Element; 2.43 +import javax.lang.model.element.ElementKind; 2.44 +import javax.tools.JavaCompiler; 2.45 +import javax.tools.JavaFileObject; 2.46 +import javax.tools.SimpleJavaFileObject; 2.47 +import javax.tools.ToolProvider; 2.48 + 2.49 +/** 2.50 + * 2.51 + * @author Jan Lahoda 2.52 + */ 2.53 +public class T6993301 { 2.54 + public static void main(String... args) throws Exception { 2.55 + new T6993301().testExceptionParameterCorrectKind(); 2.56 + } 2.57 + 2.58 + static class MyFileObject extends SimpleJavaFileObject { 2.59 + private String text; 2.60 + public MyFileObject(String text) { 2.61 + super(URI.create("myfo:/Test.java"), JavaFileObject.Kind.SOURCE); 2.62 + this.text = text; 2.63 + } 2.64 + @Override 2.65 + public CharSequence getCharContent(boolean ignoreEncodingErrors) { 2.66 + return text; 2.67 + } 2.68 + } 2.69 + 2.70 + public void testExceptionParameterCorrectKind() throws IOException { 2.71 + final String bootPath = System.getProperty("sun.boot.class.path"); 2.72 + final JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); 2.73 + assert tool != null; 2.74 + 2.75 + String code = "package test; public class Test { { try { } catch (NullPointerException ex) {} } }"; 2.76 + 2.77 + final JavacTaskImpl ct = (JavacTaskImpl)tool.getTask(null, null, null, 2.78 + Arrays.asList("-bootclasspath", bootPath), 2.79 + null, Arrays.asList(new MyFileObject(code))); 2.80 + CompilationUnitTree cut = ct.parse().iterator().next(); 2.81 + 2.82 + ct.analyze(); 2.83 + 2.84 + new TreePathScanner<Void, Void>() { 2.85 + @Override 2.86 + public Void visitVariable(VariableTree node, Void p) { 2.87 + Element el = Trees.instance(ct).getElement(getCurrentPath()); 2.88 + 2.89 + assertNotNull(el); 2.90 + assertEquals(ElementKind.EXCEPTION_PARAMETER, el.getKind()); 2.91 + 2.92 + return super.visitVariable(node, p); 2.93 + } 2.94 + }.scan(cut, null); 2.95 + } 2.96 + 2.97 + private void assertNotNull(Object o) { 2.98 + if (o == null) 2.99 + throw new AssertionError(); 2.100 + } 2.101 + 2.102 + private <T> void assertEquals(T expected, T actual) { 2.103 + if (expected == null ? actual == null : expected.equals(actual)) 2.104 + return; 2.105 + throw new AssertionError("expected: " + expected + ", actual: " + actual); 2.106 + } 2.107 + 2.108 +}