Wed, 30 Apr 2014 23:26:43 +0100
8038023: Compiler crash ClassCastException
Summary: Add additional checks on results of ClassReader.readPool
Reviewed-by: vromero
duke@1 | 1 | /* |
ohair@798 | 2 | * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
duke@1 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@1 | 4 | * |
duke@1 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@1 | 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 |
duke@1 | 8 | * particular file as subject to the "Classpath" exception as provided |
ohair@554 | 9 | * by Oracle in the LICENSE file that accompanied this code. |
duke@1 | 10 | * |
duke@1 | 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@1 | 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@1 | 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@1 | 14 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@1 | 15 | * accompanied this code). |
duke@1 | 16 | * |
duke@1 | 17 | * You should have received a copy of the GNU General Public License version |
duke@1 | 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@1 | 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@1 | 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. |
duke@1 | 24 | */ |
duke@1 | 25 | |
duke@1 | 26 | package com.sun.tools.javac.main; |
duke@1 | 27 | |
duke@1 | 28 | import java.io.IOException; |
duke@1 | 29 | import java.io.Reader; |
duke@1 | 30 | import java.io.FileReader; |
duke@1 | 31 | import java.io.BufferedReader; |
duke@1 | 32 | import java.io.StreamTokenizer; |
duke@1 | 33 | import com.sun.tools.javac.util.ListBuffer; |
duke@1 | 34 | |
duke@1 | 35 | /** |
duke@1 | 36 | * Various utility methods for processing Java tool command line arguments. |
duke@1 | 37 | * |
jjg@581 | 38 | * <p><b>This is NOT part of any supported API. |
jjg@581 | 39 | * If you write code that depends on this, you do so at your own risk. |
duke@1 | 40 | * This code and its internal interfaces are subject to change or |
duke@1 | 41 | * deletion without notice.</b> |
duke@1 | 42 | */ |
duke@1 | 43 | public class CommandLine { |
duke@1 | 44 | /** |
duke@1 | 45 | * Process Win32-style command files for the specified command line |
duke@1 | 46 | * arguments and return the resulting arguments. A command file argument |
duke@1 | 47 | * is of the form '@file' where 'file' is the name of the file whose |
duke@1 | 48 | * contents are to be parsed for additional arguments. The contents of |
duke@1 | 49 | * the command file are parsed using StreamTokenizer and the original |
duke@1 | 50 | * '@file' argument replaced with the resulting tokens. Recursive command |
duke@1 | 51 | * files are not supported. The '@' character itself can be quoted with |
duke@1 | 52 | * the sequence '@@'. |
duke@1 | 53 | */ |
duke@1 | 54 | public static String[] parse(String[] args) |
duke@1 | 55 | throws IOException |
duke@1 | 56 | { |
duke@1 | 57 | ListBuffer<String> newArgs = new ListBuffer<String>(); |
duke@1 | 58 | for (int i = 0; i < args.length; i++) { |
duke@1 | 59 | String arg = args[i]; |
duke@1 | 60 | if (arg.length() > 1 && arg.charAt(0) == '@') { |
duke@1 | 61 | arg = arg.substring(1); |
duke@1 | 62 | if (arg.charAt(0) == '@') { |
duke@1 | 63 | newArgs.append(arg); |
duke@1 | 64 | } else { |
duke@1 | 65 | loadCmdFile(arg, newArgs); |
duke@1 | 66 | } |
duke@1 | 67 | } else { |
duke@1 | 68 | newArgs.append(arg); |
duke@1 | 69 | } |
duke@1 | 70 | } |
duke@1 | 71 | return newArgs.toList().toArray(new String[newArgs.length()]); |
duke@1 | 72 | } |
duke@1 | 73 | |
duke@1 | 74 | private static void loadCmdFile(String name, ListBuffer<String> args) |
duke@1 | 75 | throws IOException |
duke@1 | 76 | { |
duke@1 | 77 | Reader r = new BufferedReader(new FileReader(name)); |
duke@1 | 78 | StreamTokenizer st = new StreamTokenizer(r); |
duke@1 | 79 | st.resetSyntax(); |
duke@1 | 80 | st.wordChars(' ', 255); |
duke@1 | 81 | st.whitespaceChars(0, ' '); |
duke@1 | 82 | st.commentChar('#'); |
duke@1 | 83 | st.quoteChar('"'); |
duke@1 | 84 | st.quoteChar('\''); |
jjg@507 | 85 | while (st.nextToken() != StreamTokenizer.TT_EOF) { |
duke@1 | 86 | args.append(st.sval); |
duke@1 | 87 | } |
duke@1 | 88 | r.close(); |
duke@1 | 89 | } |
duke@1 | 90 | } |