Wed, 30 Apr 2014 23:26:43 +0100
8038023: Compiler crash ClassCastException
Summary: Add additional checks on results of ClassReader.readPool
Reviewed-by: vromero
1 /*
2 * Copyright (c) 2009, 2012, 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. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
26 package com.sun.tools.javac.nio;
28 import java.io.IOException;
29 import java.nio.file.FileSystem;
30 import java.nio.file.FileSystems;
31 import java.nio.file.Path;
32 import javax.tools.FileObject;
33 import javax.tools.JavaFileManager;
34 import javax.tools.JavaFileObject;
36 /**
37 * File manager based on {@link java.nio.file.Path}.
38 *
39 * Eventually, this should be moved to javax.tools.
40 * Also, JavaCompiler might reasonably provide a method getPathFileManager,
41 * similar to {@link javax.tools.JavaCompiler#getStandardFileManager
42 * getStandardFileManager}. However, would need to be handled carefully
43 * as another forward reference from langtools to jdk.
44 *
45 * <p><b>This is NOT part of any supported API.
46 * If you write code that depends on this, you do so at your own risk.
47 * This code and its internal interfaces are subject to change or
48 * deletion without notice.</b>
49 */
50 public interface PathFileManager extends JavaFileManager {
51 /**
52 * Get the default file system used to create paths. If no value has been
53 * set, the default file system is {@link FileSystems#getDefault}.
54 */
55 FileSystem getDefaultFileSystem();
57 /**
58 * Set the default file system used to create paths.
59 * @param fs the default file system used to create any new paths.
60 */
61 void setDefaultFileSystem(FileSystem fs);
63 /**
64 * Get file objects representing the given files.
65 *
66 * @param paths a list of paths
67 * @return a list of file objects
68 * @throws IllegalArgumentException if the list of paths includes
69 * a directory
70 */
71 Iterable<? extends JavaFileObject> getJavaFileObjectsFromPaths(
72 Iterable<? extends Path> paths);
74 /**
75 * Get file objects representing the given paths.
76 * Convenience method equivalent to:
77 *
78 * <pre>
79 * getJavaFileObjectsFromPaths({@linkplain java.util.Arrays#asList Arrays.asList}(paths))
80 * </pre>
81 *
82 * @param paths an array of paths
83 * @return a list of file objects
84 * @throws IllegalArgumentException if the array of files includes
85 * a directory
86 * @throws NullPointerException if the given array contains null
87 * elements
88 */
89 Iterable<? extends JavaFileObject> getJavaFileObjects(Path... paths);
91 /**
92 * Return the Path for a file object that has been obtained from this
93 * file manager.
94 *
95 * @param fo A file object that has been obtained from this file manager.
96 * @return The underlying Path object.
97 * @throws IllegalArgumentException is the file object was not obtained from
98 * from this file manager.
99 */
100 Path getPath(FileObject fo);
102 /**
103 * Get the search path associated with the given location.
104 *
105 * @param location a location
106 * @return a list of paths or {@code null} if this location has no
107 * associated search path
108 * @see #setLocation
109 */
110 Iterable<? extends Path> getLocation(Location location);
112 /**
113 * Associate the given search path with the given location. Any
114 * previous value will be discarded.
115 *
116 * @param location a location
117 * @param searchPath a list of files, if {@code null} use the default
118 * search path for this location
119 * @see #getLocation
120 * @throws IllegalArgumentException if location is an output
121 * location and searchpath does not contain exactly one element
122 * @throws IOException if location is an output location and searchpath
123 * does not represent an existing directory
124 */
125 void setLocation(Location location, Iterable<? extends Path> searchPath) throws IOException;
126 }