hotspot/test/runtime/classFileParserBug/InitInInterface.java
author jprovino
Wed, 11 Nov 2015 23:47:42 +0000
changeset 33911 af2cff5bd523
parent 33207 edc4431940b2
child 41705 332239c052cc
permissions -rw-r--r--
Merge
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
33207
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     1
/*
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     2
 * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     4
 *
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     7
 * published by the Free Software Foundation.
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     8
 *
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    13
 * accompanied this code).
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    14
 *
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    18
 *
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    21
 * questions.
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    22
 *
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    23
 */
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    24
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    25
/*
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    26
 * @test
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    27
 * @bug 8139069
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    28
 * @summary Check that any method named <init> in an interface causes ClassFormatError
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    29
 * @compile nonvoidinit.jasm voidinit.jasm
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    30
 * @run main InitInInterface
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    31
 */
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    32
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    33
// Test that an <init> method is not allowed in interfaces.
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    34
public class InitInInterface {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    35
    public static void main(String args[]) throws Throwable {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    36
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    37
        System.out.println("Regression test for bug 8130183");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    38
        try {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    39
            Class newClass = Class.forName("nonvoidinit");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    40
            throw new RuntimeException(
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    41
                 "ClassFormatError not thrown for non-void <init> in an interface");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    42
        } catch (java.lang.ClassFormatError e) {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    43
            if (!e.getMessage().contains("Interface cannot have a method named <init>")) {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    44
                throw new RuntimeException("Unexpected exception nonvoidint: " + e.getMessage());
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    45
            }
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    46
        }
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    47
        try {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    48
            Class newClass = Class.forName("voidinit");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    49
            throw new RuntimeException(
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    50
                 "ClassFormatError not thrown for void <init> in an interface");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    51
        } catch (java.lang.ClassFormatError e) {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    52
            if (!e.getMessage().contains("Interface cannot have a method named <init>")) {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    53
                throw new RuntimeException("Unexpected exception voidint: " + e.getMessage());
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    54
            }
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    55
        }
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    56
    }
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    57
}