BadInitMethod.java revision 12158:0fe2815ffa74
1139823Simp/* 21541Srgrimes * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 31541Srgrimes * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 41541Srgrimes * 51541Srgrimes * This code is free software; you can redistribute it and/or modify it 61541Srgrimes * under the terms of the GNU General Public License version 2 only, as 71541Srgrimes * published by the Free Software Foundation. 81541Srgrimes * 91541Srgrimes * This code is distributed in the hope that it will be useful, but WITHOUT 101541Srgrimes * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 111541Srgrimes * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 121541Srgrimes * version 2 for more details (a copy is included in the LICENSE file that 131541Srgrimes * accompanied this code). 141541Srgrimes * 151541Srgrimes * You should have received a copy of the GNU General Public License version 161541Srgrimes * 2 along with this work; if not, write to the Free Software Foundation, 171541Srgrimes * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 181541Srgrimes * 191541Srgrimes * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 201541Srgrimes * or visit www.oracle.com if you need additional information or have any 211541Srgrimes * questions. 221541Srgrimes */ 231541Srgrimes 241541Srgrimes/* 251541Srgrimes * @test 261541Srgrimes * @bug 8130669 271541Srgrimes * @summary VM prohibits <clinit> methods with return values 281541Srgrimes * @compile nonvoidClinit.jasm 291541Srgrimes * @compile clinitNonStatic.jasm 301541Srgrimes * @compile clinitArg.jasm 311541Srgrimes * @compile clinitArg51.jasm 3222521Sdyson * @compile badInit.jasm 331541Srgrimes * @run main/othervm -Xverify:all BadInitMethod 341541Srgrimes */ 3583651Speter 3683654Speter// Test that non-void <clinit>, non-static <clinit>, and non-void 3722521Sdyson// <init> methods cause ClassFormatException's to be thrown. 38190380Srwatsonpublic class BadInitMethod { 39190380Srwatson public static void main(String args[]) throws Throwable { 401541Srgrimes 411541Srgrimes System.out.println("Regression test for bug 8130669"); 4279247Sjhb try { 4379247Sjhb Class newClass = Class.forName("nonvoidClinit"); 4479247Sjhb throw new RuntimeException( 45192578Srwatson "Expected ClassFormatError exception for non-void <clinit> not thrown"); 4679247Sjhb } catch (java.lang.ClassFormatError e) { 4779247Sjhb System.out.println("Test BadInitMethod passed for non-void <clinit>"); 4879247Sjhb } 491541Srgrimes 501541Srgrimes try { 511541Srgrimes Class newClass = Class.forName("clinitNonStatic"); 52239065Skib throw new RuntimeException( 5312662Sdg "Expected ClassFormatError exception for non-static <clinit> not thrown"); 5425930Sdfr } catch (java.lang.ClassFormatError e) { 5525930Sdfr System.out.println("Test BadInitMethod passed for non-static <clinit>"); 5625930Sdfr } 5725930Sdfr 581541Srgrimes // <clinit> with args is allowed in class file version < 51. 599336Sdfr try { 6083651Speter Class newClass = Class.forName("clinitArg"); 6183651Speter } catch (java.lang.ClassFormatError e) { 6283651Speter throw new RuntimeException( 63221543Srmacklem "Unexpected ClassFormatError exception for <clinit> with argument in class file < 51"); 641541Srgrimes } 6583651Speter 6683651Speter // <clinit> with args is not allowed in class file version >= 51. 67138899Sps try { 68138899Sps Class newClass = Class.forName("clinitArg51"); 6975580Sphk throw new RuntimeException( 70138899Sps "Expected ClassFormatError exception for <clinit> with argument not thrown"); 71138899Sps } catch (java.lang.ClassFormatError e) { 72158739Smohans System.out.println("Test BadInitMethod passed for <clinit> with argument"); 731541Srgrimes } 7425930Sdfr 7525930Sdfr try { 7625930Sdfr Class newClass = Class.forName("badInit"); 7783651Speter throw new RuntimeException( 7825930Sdfr "Expected ClassFormatError exception for non-void <init> not thrown"); 7946349Salc } catch (java.lang.ClassFormatError e) { 8032755Sdyson System.out.println("Test BadInitMethod passed for non-void <init>"); 8132755Sdyson } 8232755Sdyson } 8334206Sdyson} 8436563Speter