langtools/test/tools/javap/T7004698.java
author jjg
Wed, 10 Aug 2016 15:47:46 -0700
changeset 40308 274367a99f98
parent 36526 3b41f1c69604
child 43258 45757c4367f2
permissions -rw-r--r--
8136930: Simplify use of module-system options by custom launchers 8160489: Multiple -Xpatch lines ignored by javac 8156998: javac should support new option -XinheritRuntimeEnvironment Reviewed-by: jlahoda, ksrini
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     1
/*
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
     2
 * Copyright (c) 2010, 2016, Oracle and/or its affiliates. All rights reserved.
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     4
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     8
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    13
 * accompanied this code).
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    14
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    18
 *
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    21
 * questions.
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    22
 */
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    23
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    24
/*
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    25
 * @test
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    26
 * @bug 7004698
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    27
 * @summary javap does not output CharacterRangeTable attributes correctly
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.javap
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    29
 */
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    30
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    31
import java.io.*;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    32
import java.util.*;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    33
import java.util.regex.*;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    34
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    35
public class T7004698 {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    36
    public static void main(String... args) throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    37
        new T7004698().run();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    38
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    39
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    40
    void run() throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    41
        File srcDir = new File(System.getProperty("test.src"));
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    42
        File srcFile = new File(srcDir, T7004698.class.getSimpleName() + ".java");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    43
        File classesDir = new File(".");
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
    44
        compile("-Xjcov",
40308
274367a99f98 8136930: Simplify use of module-system options by custom launchers
jjg
parents: 36526
diff changeset
    45
                "--add-exports", "jdk.jdeps/com.sun.tools.javap=ALL-UNNAMED",
36526
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
    46
                "-d", classesDir.getPath(),
3b41f1c69604 8142968: Module System implementation
alanb
parents: 30846
diff changeset
    47
                srcFile.getPath());
7625
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    48
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    49
        File classFile = new File(classesDir, T7004698.class.getSimpleName() + ".class");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    50
        String out = javap("-v", classFile.getPath());
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    51
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    52
        Pattern attrBody = Pattern.compile("[0-9a-f, ]+//[-0-9a-z:, ]+");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    53
        Pattern endOfAttr = Pattern.compile("(^$|[A-Z][A-Za-z0-9_]+:.*|})");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    54
        boolean inAttr = false;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    55
        int count = 0;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    56
        int errors = 0;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    57
        for (String line: out.split(System.getProperty("line.separator"))) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    58
            line = line.trim();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    59
            if (line.equals("CharacterRangeTable:")) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    60
                inAttr = true;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    61
                count++;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    62
            } else if (inAttr) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    63
                if (endOfAttr.matcher(line).matches()) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    64
                    inAttr = false;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    65
                } else if (!attrBody.matcher(line).matches()) {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    66
                    System.err.println("unexpected line found: " + line);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    67
                    errors++;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    68
                }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    69
            }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    70
        }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    71
        if (count == 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    72
            throw new Exception("no attribute instances found");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    73
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    74
        if (errors > 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    75
            throw new Exception(errors + " errors found");
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    76
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    77
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    78
    void compile(String... args) throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    79
        StringWriter sw = new StringWriter();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    80
        PrintWriter pw = new PrintWriter(sw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    81
        int rc = com.sun.tools.javac.Main.compile(args, pw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    82
        pw.close();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    83
        String out = sw.toString();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    84
        if (!out.isEmpty())
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    85
            System.err.println(out);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    86
        if (rc != 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    87
            throw new Exception("javac failed unexpectedly; rc=" + rc);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    88
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    89
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    90
    String javap(String... args) throws Exception {
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    91
        StringWriter sw = new StringWriter();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    92
        PrintWriter pw = new PrintWriter(sw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    93
        int rc = com.sun.tools.javap.Main.run(args, pw);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    94
        pw.close();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    95
        String out = sw.toString();
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    96
        if (!out.isEmpty())
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    97
            System.err.println(out);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    98
        if (rc != 0)
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
    99
            throw new Exception("javap failed unexpectedly; rc=" + rc);
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
   100
        return out;
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
   101
    }
f7374a9d9cc9 7004698: javap does not output CharacterRangeTable attributes correctly
jjg
parents:
diff changeset
   102
}