hotspot/test/runtime/classFileParserBug/InitInInterface.java
author alanb
Fri, 07 Apr 2017 08:04:46 +0000
changeset 44520 0553e129e0ec
parent 41705 332239c052cc
permissions -rw-r--r--
8177530: Module system implementation refresh (4/2017) Reviewed-by: lfoltan, sspitsyn Contributed-by: alan.bateman@oracle.com, harold.seigel@oracle.com, mandy.chung@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
}