1 /* 2 * Copyright (c) 2020, 2024, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 * 23 */ 24 /* 25 * @ignore Fix JDK-8328419 26 * @test 27 * @bug 8243204 28 * @summary test that the JVM detects illegal super classes for value object 29 * and primitive value types. 30 * @enablePreview 31 * @compile NotAbstract.java HasNonStaticFields.java CtorHasArgs.java CtorIsNotEmpty.java 32 * @compile HasSynchMethod.java ValidSuper.java 33 * @compile InlineClassWithBadSupers.jcod 34 * @run main/othervm -verify TestSuperClasses 35 */ 36 37 public class TestSuperClasses { 38 39 public static void runTestIncompatibleClassChangeError(String test_name, String message) throws Exception { 40 System.out.println("Testing: " + test_name); 41 try { 42 Class newClass = Class.forName(test_name); 43 throw new RuntimeException("Expected IncompatibleClassChangeError exception not thrown"); 44 } catch (java.lang.IncompatibleClassChangeError e) { 45 if (!e.getMessage().contains(message)) { 46 throw new RuntimeException("Wrong IncompatibleClassChangeError: " + e.getMessage()); 47 } 48 } 49 } 50 51 public static void main(String[] args) throws Exception { 52 53 // Value Objects... 54 55 // Test that the super class of an value type must be java.lang.Object or an abstract class. 56 runTestIncompatibleClassChangeError("ValueSuperNotAbstract", 57 "Value type ValueSuperNotAbstract has an identity type as supertype"); 58 59 // Test that the super class of an value type cannot have instance fields. 60 runTestIncompatibleClassChangeError("ValueSuperHasNonStaticFields", 61 "Value type ValueSuperHasNonStaticFields has an identity type as supertype"); 62 63 // Test that the super class of an value type cannot contain a synchronized instance method. 64 runTestIncompatibleClassChangeError("ValueSuperHasSynchMethod", 65 "Value type ValueSuperHasSynchMethod has an identity type as supertype"); 66 67 // Test that the constructor in a super class of an value type must have a signature of "()V". 68 runTestIncompatibleClassChangeError("ValueSuperCtorHasArgs", 69 "Value type ValueSuperCtorHasArgs has an identity type as supertype"); 70 71 // Test that the constructor in a super class of an value type must be empty. 72 runTestIncompatibleClassChangeError("ValueSuperCtorIsNotEmpty", 73 "Value type ValueSuperCtorIsNotEmpty has an identity type as supertype"); 74 75 // Primitive values... 76 77 // Test that the super class of an primitive value type must be java.lang.Object or an abstract class. 78 runTestIncompatibleClassChangeError("PrimitiveSuperNotAbstract", 79 "Value type PrimitiveSuperNotAbstract has an identity type as supertype"); 80 81 // Test that the super class of an primitive value type cannot have instance fields. 82 runTestIncompatibleClassChangeError("PrimitiveSuperHasNonStaticFields", 83 "Value type PrimitiveSuperHasNonStaticFields has an identity type as supertype"); 84 85 // Test that the super class of an primitive value type cannot contain a synchronized instance method. 86 runTestIncompatibleClassChangeError("PrimitiveSuperHasSynchMethod", 87 "Value type PrimitiveSuperHasSynchMethod has an identity type as supertype"); 88 89 // Test that the constructor in a super class of an primitive value type must have a signature of "()V". 90 runTestIncompatibleClassChangeError("PrimitiveSuperCtorHasArgs", 91 "Value type PrimitiveSuperCtorHasArgs has an identity type as supertype"); 92 93 // Test that the constructor in a super class of an primitive value type must be empty. 94 runTestIncompatibleClassChangeError("PrimitiveSuperCtorIsNotEmpty", 95 "Value type PrimitiveSuperCtorIsNotEmpty has an identity type as supertype"); 96 } 97 }