langtools/test/tools/javap/T6980017.java
author jjg
Thu, 16 Sep 2010 09:57:37 -0700
changeset 6601 90c4a1a64217
parent 6578 964b4d71d26f
child 30730 d3ce7619db2c
permissions -rw-r--r--
6985115: tests create too much output Reviewed-by: mcimadamore
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6578
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     1
/*
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     2
 * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     4
 *
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     8
 *
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    13
 * accompanied this code).
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    14
 *
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    18
 *
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    21
 * questions.
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    22
 */
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    23
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    24
/*
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    25
 * @test
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    26
 * @bug 6980017
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    27
 * @summary javap -XDdetail:source behaves badly if source not available.
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    28
 */
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    29
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    30
import java.io.*;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    31
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    32
public class T6980017 {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    33
    public static void main(String... args) throws Exception {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    34
        new T6980017().run();
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    35
    }
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    36
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    37
    void run() throws Exception {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    38
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    39
        String[] args = {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    40
            "-v",
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    41
            "-XDdetails:source",
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 6578
diff changeset
    42
            "java.lang.Object"
6578
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    43
        };
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    44
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    45
        StringWriter sw = new StringWriter();
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    46
        PrintWriter pw = new PrintWriter(sw);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    47
        int rc = com.sun.tools.javap.Main.run(args, pw);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    48
        pw.close();
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    49
        if (rc != 0)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    50
            error("Unexpected exit code: " + rc);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    51
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    52
        boolean foundBlankSourceLine = false;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    53
        boolean foundNoSourceLine = false;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    54
        for (String line: sw.toString().split("[\r\n]+")) {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    55
            System.err.println(line);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    56
            if (line.contains("Source code not available"))
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    57
                foundNoSourceLine = true;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    58
            if (line.matches("\\s*\\( *[0-9]+\\)\\s*"))
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    59
                foundBlankSourceLine = true;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    60
        }
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    61
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    62
        if (foundBlankSourceLine)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    63
            error("found blank source lines");
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    64
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    65
        if (!foundNoSourceLine)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    66
            error("did not find \"Source code not available\" message");
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    67
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    68
        if (errors > 0)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    69
            throw new Exception(errors + " errors occurred");
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    70
    }
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    71
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    72
    void error(String msg) {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    73
        System.err.println(msg);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    74
        errors++;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    75
    }
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    76
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    77
    int errors;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    78
}