hotspot/test/runtime/classFileParserBug/InitInInterface.java
author stsmirno
Mon, 17 Oct 2016 18:54:12 -0400
changeset 41705 332239c052cc
parent 33207 edc4431940b2
permissions -rw-r--r--
8165687: Fix license and copyright headers in jd9 under hotspot/test Summary: Legal notices and Oracle copyrights were updated (white and blank space, commas) in tests files for uniformity to meet Oracle requirements. Reviewed-by: dholmes, iris Contributed-by: Stanislav Smirnov <stanislav.smirnov@oracle.com>, Vassili Igouchkine <vassili.igouchkine@oracle.com>
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
 * @test
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    26
 * @bug 8139069
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    27
 * @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
    28
 * @compile nonvoidinit.jasm voidinit.jasm
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    29
 * @run main InitInInterface
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    30
 */
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
// 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
    33
public class InitInInterface {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    34
    public static void main(String args[]) throws Throwable {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    35
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    36
        System.out.println("Regression test for bug 8130183");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    37
        try {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    38
            Class newClass = Class.forName("nonvoidinit");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    39
            throw new RuntimeException(
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    40
                 "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
    41
        } catch (java.lang.ClassFormatError e) {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    42
            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
    43
                throw new RuntimeException("Unexpected exception nonvoidint: " + e.getMessage());
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    44
            }
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
        try {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    47
            Class newClass = Class.forName("voidinit");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    48
            throw new RuntimeException(
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    49
                 "ClassFormatError not thrown for void <init> in an interface");
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    50
        } catch (java.lang.ClassFormatError e) {
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    51
            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
    52
                throw new RuntimeException("Unexpected exception voidint: " + e.getMessage());
edc4431940b2 8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
diff changeset
    53
            }
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
}