Path: blob/aarch64-shenandoah-jdk8u272-b10/langtools/test/tools/javac/6330997/T6330997.java
38813 views
/*1* Copyright (c) 2006, 2011, 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 6330997 702578926* @summary javac should accept class files with major version of the next release27* @author Wei Tao28* @clean T1 T229* @compile -target 8 T1.java30* @compile -target 8 T2.java31* @run main/othervm T633099732*/3334import java.nio.*;35import java.io.*;36import java.nio.channels.*;37import com.sun.tools.javac.api.JavacTaskImpl;38import com.sun.tools.javac.jvm.ClassReader.BadClassFile;39import com.sun.tools.javac.main.JavaCompiler;40import javax.tools.ToolProvider;4142public class T6330997 {43public static void main(String... args) {44increaseMajor("T1.class", 1);45increaseMajor("T2.class", 2);46javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();47JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);48JavaCompiler compiler = JavaCompiler.instance(task.getContext());49try {50compiler.resolveIdent("T1").complete();51} catch (Exception e) {52e.printStackTrace();53throw new RuntimeException("Failed: unexpected exception while reading class T1");54}55try {56compiler.resolveIdent("T2").complete();57} catch (BadClassFile e) {58System.err.println("Passed: expected completion failure " + e.getClass().getName());59return;60} catch (Exception e) {61e.printStackTrace();62throw new RuntimeException("Failed: unexpected exception while reading class T2");63}64throw new RuntimeException("Failed: no error reported");65}6667// Increase class file cfile's major version by delta68static void increaseMajor(String cfile, int delta) {69try {70RandomAccessFile cls = new RandomAccessFile(71new File(System.getProperty("test.classes", "."), cfile), "rw");72FileChannel fc = cls.getChannel();73ByteBuffer rbuf = ByteBuffer.allocate(2);74fc.read(rbuf, 6);75ByteBuffer wbuf = ByteBuffer.allocate(2);76wbuf.putShort(0, (short)(rbuf.getShort(0) + delta));77fc.write(wbuf, 6);78fc.force(false);79cls.close();80} catch (Exception e){81e.printStackTrace();82throw new RuntimeException("Failed: unexpected exception");83}84}85}868788