mcimadamore@303: /* ohair@554: * Copyright (c) 2009, Oracle and/or its affiliates. All rights reserved. mcimadamore@303: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. mcimadamore@303: * mcimadamore@303: * This code is free software; you can redistribute it and/or modify it mcimadamore@303: * under the terms of the GNU General Public License version 2 only, as mcimadamore@303: * published by the Free Software Foundation. mcimadamore@303: * mcimadamore@303: * This code is distributed in the hope that it will be useful, but WITHOUT mcimadamore@303: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or mcimadamore@303: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License mcimadamore@303: * version 2 for more details (a copy is included in the LICENSE file that mcimadamore@303: * accompanied this code). mcimadamore@303: * mcimadamore@303: * You should have received a copy of the GNU General Public License version mcimadamore@303: * 2 along with this work; if not, write to the Free Software Foundation, mcimadamore@303: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. mcimadamore@303: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. mcimadamore@303: */ mcimadamore@303: mcimadamore@303: /* mcimadamore@303: * @test mcimadamore@303: * @bug 6852595 mcimadamore@303: * @summary Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception mcimadamore@303: * @author mcimadamore mcimadamore@303: */ mcimadamore@303: mcimadamore@303: import java.io.IOException; mcimadamore@303: import java.net.URI; mcimadamore@303: import java.util.Arrays; mcimadamore@303: import java.util.List; mcimadamore@303: import javax.tools.JavaCompiler; mcimadamore@303: import javax.tools.JavaFileObject; mcimadamore@303: import javax.tools.SimpleJavaFileObject; mcimadamore@303: import javax.tools.ToolProvider; mcimadamore@303: mcimadamore@303: import com.sun.source.util.JavacTask; mcimadamore@303: import com.sun.source.tree.*; mcimadamore@303: import com.sun.source.util.TreePath; mcimadamore@303: import com.sun.source.util.Trees; mcimadamore@303: import com.sun.tools.javac.api.JavacTrees; mcimadamore@303: import com.sun.tools.javac.tree.JCTree.*; mcimadamore@303: mcimadamore@303: import static javax.tools.JavaFileObject.Kind; mcimadamore@303: mcimadamore@303: public class T6852595 { mcimadamore@303: public static void main(String[] args) throws IOException { mcimadamore@303: JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) { mcimadamore@303: public CharSequence getCharContent(boolean ignoreEncodingErrors) { mcimadamore@303: return "class BadName { Object o = j; }"; mcimadamore@303: } mcimadamore@303: }; mcimadamore@303: List files = Arrays.asList(sfo); mcimadamore@303: JavaCompiler tool = ToolProvider.getSystemJavaCompiler(); mcimadamore@303: JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files); mcimadamore@303: Iterable compUnits = ct.parse(); mcimadamore@303: CompilationUnitTree cu = compUnits.iterator().next(); mcimadamore@303: ClassTree cdef = (ClassTree)cu.getTypeDecls().get(0); mcimadamore@303: JCVariableDecl vdef = (JCVariableDecl)cdef.getMembers().get(0); mcimadamore@303: TreePath path = TreePath.getPath(cu, vdef.init); mcimadamore@303: Trees.instance(ct).getScope(path); mcimadamore@303: } mcimadamore@303: }