test/hotspot/jtreg/runtime/classFileParserBug/TestBadClassName.java
author dholmes
Thu, 14 Feb 2019 22:57:37 -0500
changeset 53768 5f02b8c98b35
parent 47216 71c04702a3d5
permissions -rw-r--r--
8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows Reviewed-by: kbarrett, coleenp, mikael, iignatyev
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     1
/*
53768
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
     2
 * Copyright (c) 2016, 2019, Oracle and/or its affiliates. All rights reserved.
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     4
 *
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     7
 * published by the Free Software Foundation.
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     8
 *
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    13
 * accompanied this code).
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    14
 *
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    18
 *
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    21
 * questions.
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    22
 */
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    23
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    24
/*
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    25
 * @test
53768
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    26
 * @bug 8158297 8218939
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    27
 * @summary Constant pool utf8 entry for class name cannot have empty qualified name '//'
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    28
 * @compile p1/BadInterface1.jcod
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    29
 * @compile p1/BadInterface2.jcod
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    30
 * @compile UseBadInterface1.jcod
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    31
 * @compile UseBadInterface2.jcod
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    32
 * @run main/othervm -Xverify:all TestBadClassName
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    33
 */
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    34
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    35
public class TestBadClassName {
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    36
    public static void main(String args[]) throws Throwable {
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    37
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    38
        System.out.println("Regression test for bug 8042660");
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    39
53768
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    40
        // Test class name with p1//BadInterface1
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    41
        String expected = "Illegal class name \"p1//BadInterface1\" in class file UseBadInterface1";
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    42
        try {
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    43
            Class newClass = Class.forName("UseBadInterface1");
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    44
            throw new RuntimeException("Expected ClassFormatError exception not thrown");
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    45
        } catch (java.lang.ClassFormatError e) {
53768
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    46
            check(e, expected);
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    47
            System.out.println("Test UseBadInterface1 passed test case with illegal class name");
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    48
        }
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    49
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    50
        // Test class name with p1/BadInterface2/
53768
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    51
        expected = "Illegal class name \"p1/BadInterface2/\" in class file UseBadInterface2";
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    52
        try {
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    53
            Class newClass = Class.forName("UseBadInterface2");
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    54
            throw new RuntimeException("Expected ClassFormatError exception not thrown");
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    55
        } catch (java.lang.ClassFormatError e) {
53768
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    56
            check(e, expected);
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    57
            System.out.println("Test UseBadInterface2 passed test case with illegal class name");
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    58
        }
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    59
    }
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    60
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    61
    static void check(ClassFormatError c, String expected) {
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    62
        if (!c.getMessage().equals(expected)) {
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    63
            throw new RuntimeException("Wrong ClassFormatError - expected: \"" +
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    64
                                       expected + "\", got \"" +
5f02b8c98b35 8218939: vm/mlvm/anonloader/stress/byteMutation crashed on windows
dholmes
parents: 47216
diff changeset
    65
                                       c.getMessage() + "\"");
39218
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    66
        }
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    67
    }
43ac06a5ee4f 8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
diff changeset
    68
}