langtools/test/tools/javap/T7186925.java
author serb
Thu, 14 Jan 2016 23:14:01 +0300
changeset 35687 78e8e8fea09b
parent 30846 2b3f379840f0
child 36526 3b41f1c69604
permissions -rw-r--r--
8147407: Provide support of WaveExtensible sound format Reviewed-by: prr, amenkov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
13839
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     1
/*
30730
d3ce7619db2c 8076543: Add @modules as needed to the langtools tests
akulyakh
parents: 13839
diff changeset
     2
 * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
13839
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     4
 *
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     7
 * published by the Free Software Foundation.
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     8
 *
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    13
 * accompanied this code).
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    14
 *
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    18
 *
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    21
 * questions.
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    22
 */
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    23
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    24
/*
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    25
 * @test
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    26
 * @bug 7186925
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    27
 * @summary JavapTask passes null to java.io.Writer
30846
2b3f379840f0 8074432: Move jdeps and javap to jdk.jdeps module
mchung
parents: 30730
diff changeset
    28
 * @modules jdk.jdeps/com.sun.tools.classfile
13839
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    29
 */
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    30
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    31
import java.io.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    32
import java.util.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    33
import javax.tools.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    34
import com.sun.tools.javap.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    35
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    36
public class T7186925
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    37
{
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    38
    public static void main(String... args) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    39
        new T7186925().run();
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    40
    }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    41
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    42
    void run() {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    43
        verify("java.lang.Object");
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    44
        if (errors > 0)
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    45
            throw new Error(errors + " found.");
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    46
    }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    47
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    48
    void verify(String className) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    49
        try {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    50
            JavaFileManager fileManager = JavapFileManager.create(null, null);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    51
            JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    52
            if (fo == null) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    53
                error("Can't find " + className);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    54
            } else {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    55
                JavapTask t = new JavapTask(null, fileManager, null);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    56
                t.handleOptions(new String[] { "-sysinfo", className });
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    57
                JavapTask.ClassFileInfo cfInfo = t.read(fo);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    58
                expectEqual(cfInfo.cf.byteLength(), cfInfo.size);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    59
            }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    60
        } catch (NullPointerException ee) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    61
            ee.printStackTrace();
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    62
            error("Exception: " + ee);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    63
        } catch (Exception ee) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    64
            System.err.println("Caught exception: " + ee);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    65
        }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    66
    }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    67
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    68
    void expectEqual(int found, int expected) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    69
        if (found != expected)
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    70
            error("bad value found: " + found + " expected: " + expected);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    71
    }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    72
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    73
    void error(String msg) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    74
        System.err.println(msg);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    75
        errors++;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    76
    }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    77
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    78
    int errors;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    79
}