Path: blob/master/test/hotspot/jtreg/runtime/ClassFile/UnsupportedClassFileVersion.java
40942 views
/*1* Copyright (c) 2014, 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* @library /test/lib26* @modules java.base/jdk.internal.org.objectweb.asm27* java.base/jdk.internal.misc28* java.management29* @compile -XDignore.symbol.file UnsupportedClassFileVersion.java30* @run main UnsupportedClassFileVersion31*/3233import java.io.File;34import java.io.FileOutputStream;35import jdk.internal.org.objectweb.asm.ClassWriter;36import jdk.internal.org.objectweb.asm.MethodVisitor;37import jdk.internal.org.objectweb.asm.Opcodes;38import jdk.test.lib.process.ProcessTools;39import jdk.test.lib.process.OutputAnalyzer;4041public class UnsupportedClassFileVersion implements Opcodes {42public static void main(String... args) throws Exception {43writeClassFile();44ProcessBuilder pb = ProcessTools.createTestJvm("-cp", ".", "ClassFile");45OutputAnalyzer output = new OutputAnalyzer(pb.start());46output.shouldContain("ClassFile has been compiled by a more recent version of the " +47"Java Runtime (class file version 99.0), this version of " +48"the Java Runtime only recognizes class file versions up to " +49System.getProperty("java.class.version"));5051output.shouldHaveExitValue(1);52}5354public static void writeClassFile() throws Exception {55ClassWriter cw = new ClassWriter(0);56MethodVisitor mv;5758cw.visit(99, ACC_PUBLIC + ACC_SUPER, "ClassFile", null, "java/lang/Object", null);59mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);60mv.visitCode();61mv.visitVarInsn(ALOAD, 0);62mv.visitMethodInsn(INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false);63mv.visitInsn(RETURN);64mv.visitMaxs(1, 1);65mv.visitEnd();66cw.visitEnd();6768try (FileOutputStream fos = new FileOutputStream(new File("ClassFile.class"))) {69fos.write(cw.toByteArray());70}71}72}737475