Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javap/T6866657.java
32285 views
/*1* Copyright (c) 2009, 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*/222324/*25* @test26* @bug 686665727* @summary add byteLength() method to primary classfile types28*/2930import java.io.*;31import java.util.*;32import javax.tools.*;33import com.sun.tools.javap.*;3435public class T686665736{37public static void main(String... args) {38new T6866657().run();39}4041void run() {42verify("java.lang.Object");43verify("java.lang.String");44verify("java.util.List");45verify("java.util.ArrayList");46if (errors > 0)47throw new Error(errors + " found.");48}4950void verify(String className) {51try {52PrintWriter log = new PrintWriter(System.out);53JavaFileManager fileManager = JavapFileManager.create(null, log);54JavaFileObject fo = fileManager.getJavaFileForInput(StandardLocation.PLATFORM_CLASS_PATH, className, JavaFileObject.Kind.CLASS);55if (fo == null) {56error("Can't find " + className);57} else {58JavapTask t = new JavapTask(log, fileManager, null);59t.handleOptions(new String[] { "-sysinfo", className });60JavapTask.ClassFileInfo cfInfo = t.read(fo);61expectEqual(cfInfo.cf.byteLength(), cfInfo.size);62}63} catch (Exception e) {64e.printStackTrace();65error("Exception: " + e);66}67}6869void expectEqual(int found, int expected) {70if (found != expected)71error("bad value found: " + found + " expected: " + expected);72}7374void error(String msg) {75System.err.println(msg);76errors++;77}7879int errors;80}81828384