Path: blob/master/test/langtools/tools/javap/T6866657.java
41144 views
/*1* Copyright (c) 2009, 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 686665726* @summary add byteLength() method to primary classfile types27* @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 T686665737{38public static void main(String... args) {39new T6866657().run();40}4142void run() {43verify("java.lang.Object");44verify("java.lang.String");45verify("java.util.List");46verify("java.util.ArrayList");47if (errors > 0)48throw new Error(errors + " found.");49}5051void verify(String className) {52try {53PrintWriter log = new PrintWriter(System.out);54JavaFileManager fileManager = JavapFileManager.create(null, log);55JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS);56if (fo == null) {57error("Can't find " + className);58} else {59JavapTask t = new JavapTask(log, fileManager, null);60t.handleOptions(new String[] { "-sysinfo", className });61JavapTask.ClassFileInfo cfInfo = t.read(fo);62expectEqual(cfInfo.cf.byteLength(), cfInfo.size);63}64} catch (Exception e) {65e.printStackTrace();66error("Exception: " + e);67}68}6970void expectEqual(int found, int expected) {71if (found != expected)72error("bad value found: " + found + " expected: " + expected);73}7475void error(String msg) {76System.err.println(msg);77errors++;78}7980int errors;81}82838485