0N/A/*
553N/A * Copyright (c) 2006, 2007, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
553N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
553N/A * or visit www.oracle.com if you need additional information or have any
553N/A * questions.
0N/A */
0N/A
0N/A/**
0N/A * @test
0N/A * @bug 6330997
0N/A * @summary javac should accept class files with major version of the next release
0N/A * @author Wei Tao
0N/A * @clean T1 T2
0N/A * @compile -target 7 T1.java
0N/A * @compile -target 7 T2.java
0N/A * @run main/othervm T6330997
0N/A */
0N/A
0N/Aimport java.nio.*;
0N/Aimport java.io.*;
0N/Aimport java.nio.channels.*;
0N/Aimport com.sun.tools.javac.api.JavacTaskImpl;
0N/Aimport com.sun.tools.javac.jvm.ClassReader.BadClassFile;
0N/Aimport com.sun.tools.javac.main.JavaCompiler;
0N/Aimport javax.tools.ToolProvider;
0N/A
0N/Apublic class T6330997 {
0N/A public static void main(String... args) {
0N/A increaseMajor("T1.class", 1);
0N/A increaseMajor("T2.class", 2);
0N/A javax.tools.JavaCompiler tool = ToolProvider.getSystemJavaCompiler();
0N/A JavacTaskImpl task = (JavacTaskImpl)tool.getTask(null, null, null, null, null, null);
0N/A JavaCompiler compiler = JavaCompiler.instance(task.getContext());
0N/A try {
0N/A compiler.resolveIdent("T1").complete();
0N/A } catch (Exception e) {
0N/A e.printStackTrace();
0N/A throw new RuntimeException("Failed: unexpected exception while reading class T1");
0N/A }
0N/A try {
0N/A compiler.resolveIdent("T2").complete();
0N/A } catch (BadClassFile e) {
0N/A System.err.println("Passed: expected completion failure " + e.getClass().getName());
0N/A return;
0N/A } catch (Exception e) {
0N/A e.printStackTrace();
0N/A throw new RuntimeException("Failed: unexpected exception while reading class T2");
0N/A }
0N/A throw new RuntimeException("Failed: no error reported");
0N/A }
0N/A
0N/A // Increase class file cfile's major version by delta
0N/A static void increaseMajor(String cfile, int delta) {
0N/A try {
0N/A RandomAccessFile cls = new RandomAccessFile(
0N/A new File(System.getProperty("test.classes", "."), cfile), "rw");
0N/A FileChannel fc = cls.getChannel();
0N/A ByteBuffer rbuf = ByteBuffer.allocate(2);
0N/A fc.read(rbuf, 6);
0N/A ByteBuffer wbuf = ByteBuffer.allocate(2);
0N/A wbuf.putShort(0, (short)(rbuf.getShort(0) + delta));
0N/A fc.write(wbuf, 6);
0N/A fc.force(false);
0N/A cls.close();
0N/A } catch (Exception e){
0N/A e.printStackTrace();
0N/A throw new RuntimeException("Failed: unexpected exception");
0N/A }
0N/A }
0N/A}