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