Path: blob/master/test/langtools/tools/javap/T7186925.java
41144 views
/*1* Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223/*24* @test25* @bug 718692526* @summary JavapTask passes null to java.io.Writer27* @modules jdk.jdeps/com.sun.tools.classfile28* jdk.jdeps/com.sun.tools.javap29*/3031import java.io.*;32import java.util.*;33import javax.tools.*;34import com.sun.tools.javap.*;3536public class T718692537{38public static void main(String... args) {39new T7186925().run();40}4142void run() {43verify("java.lang.Object");44if (errors > 0)45throw new Error(errors + " found.");46}4748void verify(String className) {49try {50JavaFileManager fileManager = JavapFileManager.create(null, null);51JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS);52if (fo == null) {53error("Can't find " + className);54} else {55JavapTask t = new JavapTask(null, fileManager, null);56t.handleOptions(new String[] { "-sysinfo", className });57JavapTask.ClassFileInfo cfInfo = t.read(fo);58expectEqual(cfInfo.cf.byteLength(), cfInfo.size);59}60} catch (NullPointerException ee) {61ee.printStackTrace();62error("Exception: " + ee);63} catch (Exception ee) {64System.err.println("Caught exception: " + ee);65}66}6768void expectEqual(int found, int expected) {69if (found != expected)70error("bad value found: " + found + " expected: " + expected);71}7273void error(String msg) {74System.err.println(msg);75errors++;76}7778int errors;79}808182