test/tools/javac/api/6852595/T6852595.java

changeset 303
8ec37cf2b37e
child 554
9d9f26857129
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/api/6852595/T6852595.java	Wed Jun 24 10:50:54 2009 +0100
     1.3 @@ -0,0 +1,66 @@
     1.4 +/*
     1.5 + * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    1.23 + * CA 95054 USA or visit www.sun.com if you need additional information or
    1.24 + * have any questions.
    1.25 + */
    1.26 +
    1.27 +/*
    1.28 + * @test
    1.29 + * @bug     6852595
    1.30 + * @summary Accessing scope using JSR199 API on erroneous tree causes Illegal Argument Exception
    1.31 + * @author  mcimadamore
    1.32 + */
    1.33 +
    1.34 +import java.io.IOException;
    1.35 +import java.net.URI;
    1.36 +import java.util.Arrays;
    1.37 +import java.util.List;
    1.38 +import javax.tools.JavaCompiler;
    1.39 +import javax.tools.JavaFileObject;
    1.40 +import javax.tools.SimpleJavaFileObject;
    1.41 +import javax.tools.ToolProvider;
    1.42 +
    1.43 +import com.sun.source.util.JavacTask;
    1.44 +import com.sun.source.tree.*;
    1.45 +import com.sun.source.util.TreePath;
    1.46 +import com.sun.source.util.Trees;
    1.47 +import com.sun.tools.javac.api.JavacTrees;
    1.48 +import com.sun.tools.javac.tree.JCTree.*;
    1.49 +
    1.50 +import static javax.tools.JavaFileObject.Kind;
    1.51 +
    1.52 +public class T6852595 {
    1.53 +    public static void main(String[] args) throws IOException {
    1.54 +        JavaFileObject sfo = new SimpleJavaFileObject(URI.create("myfo:/Test.java"),Kind.SOURCE) {
    1.55 +            public CharSequence getCharContent(boolean ignoreEncodingErrors) {
    1.56 +                return "class BadName { Object o = j; }";
    1.57 +            }
    1.58 +        };
    1.59 +        List<? extends JavaFileObject> files = Arrays.asList(sfo);
    1.60 +        JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
    1.61 +        JavacTask ct = (JavacTask)tool.getTask(null, null, null, null, null, files);
    1.62 +        Iterable<? extends CompilationUnitTree> compUnits = ct.parse();
    1.63 +        CompilationUnitTree cu = compUnits.iterator().next();
    1.64 +        ClassTree cdef = (ClassTree)cu.getTypeDecls().get(0);
    1.65 +        JCVariableDecl vdef = (JCVariableDecl)cdef.getMembers().get(0);
    1.66 +        TreePath path = TreePath.getPath(cu, vdef.init);
    1.67 +        Trees.instance(ct).getScope(path);
    1.68 +    }
    1.69 +}

mercurial