langtools/test/tools/javap/T7186925.java
author katleman
Thu, 21 Aug 2014 14:16:14 -0700
changeset 25878 6d561031123e
parent 13839 5c37d38d0aa8
child 30730 d3ce7619db2c
permissions -rw-r--r--
Added tag jdk9-b27 for changeset 98ce0879ab4c
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
/*
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
     2
 * Copyright (c) 2012, Oracle and/or its affiliates. All rights reserved.
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
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    28
 */
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
import java.io.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    31
import java.util.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    32
import javax.tools.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    33
import com.sun.tools.javap.*;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    34
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    35
public class T7186925
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    36
{
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    37
    public static void main(String... args) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    38
        new T7186925().run();
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    39
    }
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
    void run() {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    42
        verify("java.lang.Object");
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    43
        if (errors > 0)
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    44
            throw new Error(errors + " found.");
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    45
    }
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
    void verify(String className) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    48
        try {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    49
            JavaFileManager fileManager = JavapFileManager.create(null, null);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    50
            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
    51
            if (fo == null) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    52
                error("Can't find " + className);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    53
            } else {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    54
                JavapTask t = new JavapTask(null, fileManager, null);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    55
                t.handleOptions(new String[] { "-sysinfo", className });
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    56
                JavapTask.ClassFileInfo cfInfo = t.read(fo);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    57
                expectEqual(cfInfo.cf.byteLength(), cfInfo.size);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    58
            }
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    59
        } catch (NullPointerException ee) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    60
            ee.printStackTrace();
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    61
            error("Exception: " + ee);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    62
        } catch (Exception ee) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    63
            System.err.println("Caught exception: " + ee);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    64
        }
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
    void expectEqual(int found, int expected) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    68
        if (found != expected)
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    69
            error("bad value found: " + found + " expected: " + expected);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    70
    }
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
    void error(String msg) {
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    73
        System.err.println(msg);
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    74
        errors++;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    75
    }
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
    int errors;
5c37d38d0aa8 7186925: JavapTask passes null to java.io.Writer
jjg
parents:
diff changeset
    78
}