langtools/test/tools/javap/T8033180.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 22700 fff5613a52e3
child 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
22700
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     1
/*
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     2
 * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     4
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     8
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    13
 * accompanied this code).
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    14
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    18
 *
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    21
 * questions.
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    22
 */
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    23
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    24
/*
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    25
 * @test
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    26
 * @bug 8033180
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    27
 * @summary Bad newline characters
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    28
 */
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    29
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    30
import java.io.*;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    31
import java.util.*;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    32
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    33
public class T8033180 {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    34
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    35
    public static void main(String... args) throws Exception {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    36
        new T8033180().run();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    37
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    38
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    39
    void run() throws Exception {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    40
        // fast-track this case, because test cannot fail in this case
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    41
        if (lineSep.equals(nl))
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    42
            return;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    43
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    44
        test("-help");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    45
        test("-version");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    46
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    47
        if (errors > 0)
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    48
            throw new Exception(errors + " errors occurred");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    49
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    50
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    51
    static final String lineSep = System.getProperty("line.separator");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    52
    static final String nl = "\n";
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    53
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    54
    void test(String... opts) throws Exception {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    55
        System.err.println("test " + Arrays.asList(opts));
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    56
        List<String> args = new ArrayList<String>();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    57
        args.addAll(Arrays.asList(opts));
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    58
        StringWriter sw = new StringWriter();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    59
        PrintWriter pw = new PrintWriter(sw);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    60
        int rc = com.sun.tools.javap.Main.run(args.toArray(new String[args.size()]), pw);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    61
        pw.close();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    62
        String out = sw.toString();
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    63
        if (rc != 0)
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    64
            throw new Exception("javap failed unexpectedly: rc=" + rc);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    65
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    66
        // remove all valid platform newline sequences
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    67
        String out2 = out.replace(lineSep, "");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    68
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    69
        // count the remaining simple newline characters
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    70
        int count = 0;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    71
        int i = out2.indexOf(nl, 0);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    72
        while (i != -1) {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    73
            count++;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    74
            i = out2.indexOf(nl, i + nl.length());
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    75
        }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    76
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    77
        if (count > 0)
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    78
            error(count + " newline characters found");
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    79
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    80
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    81
    void error(String msg) {
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    82
        System.err.println("Error: " + msg);
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    83
        errors++;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    84
    }
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    85
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    86
    int errors = 0;
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    87
}
fff5613a52e3 8033180: An inappropriate newline symbol in the help section
jjg
parents:
diff changeset
    88