langtools/test/tools/javap/T6980017.java
author goetz
Wed, 27 Jan 2016 10:35:49 +0100
changeset 35775 00710c1b504a
parent 30730 d3ce7619db2c
child 36526 3b41f1c69604
permissions -rw-r--r--
8149529: Adapt SAP copyrights to new company name in jdk repository Reviewed-by: simonis, chegar
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
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 6601
diff changeset
     2
 * Copyright (c) 2010, 2015, Oracle and/or its affiliates. All rights reserved.
6578
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.
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 6601
diff changeset
    28
 * @modules jdk.compiler
6578
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
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    31
import java.io.*;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    32
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    33
public class T6980017 {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    34
    public static void main(String... args) throws Exception {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    35
        new T6980017().run();
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
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    38
    void run() throws Exception {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    39
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    40
        String[] args = {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    41
            "-v",
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    42
            "-XDdetails:source",
6601
90c4a1a64217 6985115: tests create too much output
jjg
parents: 6578
diff changeset
    43
            "java.lang.Object"
6578
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
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    46
        StringWriter sw = new StringWriter();
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    47
        PrintWriter pw = new PrintWriter(sw);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    48
        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
    49
        pw.close();
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    50
        if (rc != 0)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    51
            error("Unexpected exit code: " + rc);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    52
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    53
        boolean foundBlankSourceLine = false;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    54
        boolean foundNoSourceLine = false;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    55
        for (String line: sw.toString().split("[\r\n]+")) {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    56
            System.err.println(line);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    57
            if (line.contains("Source code not available"))
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    58
                foundNoSourceLine = true;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    59
            if (line.matches("\\s*\\( *[0-9]+\\)\\s*"))
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    60
                foundBlankSourceLine = true;
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
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    63
        if (foundBlankSourceLine)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    64
            error("found blank source lines");
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    65
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    66
        if (!foundNoSourceLine)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    67
            error("did not find \"Source code not available\" message");
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    68
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    69
        if (errors > 0)
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    70
            throw new Exception(errors + " errors occurred");
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
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    73
    void error(String msg) {
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    74
        System.err.println(msg);
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    75
        errors++;
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
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    78
    int errors;
964b4d71d26f 6980017: javap -XDdetail:source behaves badly if source not available.
jjg
parents:
diff changeset
    79
}