T6589361.java revision 3346:bcf9765e73b1
1/*
2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24/**
25 * @test
26 * @bug     6589361
27 * @summary 6589361:Failing building ct.sym file as part of the control build
28 * @modules jdk.compiler/com.sun.tools.javac.file
29 *          jdk.compiler/com.sun.tools.javac.util
30 */
31
32import com.sun.tools.javac.file.JavacFileManager;
33import com.sun.tools.javac.util.Context;
34import java.io.File;
35import javax.tools.FileObject;
36import javax.tools.JavaFileObject;
37import javax.tools.JavaFileObject.Kind;
38import javax.tools.StandardLocation;
39import java.util.Set;
40import java.util.HashSet;
41
42public class T6589361 {
43    public static void main(String [] args) throws Exception {
44        JavacFileManager fm = null;
45        try {
46            fm = new JavacFileManager(new Context(), false, null);
47            Set<JavaFileObject.Kind> set = new HashSet<JavaFileObject.Kind>();
48            set.add(JavaFileObject.Kind.CLASS);
49            Iterable<JavaFileObject> files = fm.list(StandardLocation.PLATFORM_CLASS_PATH, "java.lang", set, false);
50            for (JavaFileObject file : files) {
51                // Note: Zip/Jar entry names use '/', not File.separator, but just to be sure,
52                // we normalize the filename as well.
53                if (file.getName().replace(File.separatorChar, '/').contains("java/lang/Object.class")) {
54                    String str = fm.inferBinaryName(StandardLocation.PLATFORM_CLASS_PATH, file);
55                    if (!str.equals("java.lang.Object")) {
56                        System.err.println("file object: " + file);
57                        System.err.println("      class: " + file.getClass());
58                        System.err.println("       name: " + file.getName());
59                        System.err.println("binary name: " + str);
60                        throw new AssertionError("Error in JavacFileManager.inferBinaryName method!");
61                    }
62                    else {
63                        return;
64                    }
65                }
66            }
67        }
68        finally {
69            if (fm != null) {
70                fm.close();
71            }
72        }
73        throw new AssertionError("Could not find java/lang/Object.class while compiling");
74    }
75
76}
77