1 /* 2 * Copyright (c) 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 // Defines the classes used by StrictFields.java to check verification 25 // of strict fields. 26 27 // StrictIgnore is an earlier classfile version for which strict must be ignored 28 // so we can write to it multiple times in the constructor. 29 public class StrictIgnore version 66:0 { 30 final strict Field x:I; 31 32 public Method "<init>":"()V" stack 2 { 33 aload_0; 34 iconst_1; 35 putfield x:I; 36 aload_0; 37 invokespecial Method java/lang/Object."<init>":"()V"; 38 aload_0; 39 iconst_1; 40 putfield x:I; 41 return; 42 } 43 } 44 45 // StrictBase is a well formed value class with a strict field, that can 46 // be used for subclassing. 47 public abstract class StrictBase version 69:65535 { 48 protected final strict Field x:I; 49 50 public Method "<init>":"()V" stack 2 { 51 aload_0; 52 iconst_1; 53 putfield x:I; 54 aload_0; 55 invokespecial Method java/lang/Object."<init>":"()V"; 56 return; 57 } 58 } 59 60 // PostInitStrict is a bad value class that writes to a strict field after the 61 // super constructor call. 62 public final class PostInitStrict version 69:65535 { 63 final strict Field y:I; 64 65 public Method "<init>":"()V" stack 2 { 66 aload_0; 67 invokespecial Method java/lang/Object."<init>":"()V"; 68 aload_0; 69 iconst_1; 70 putfield y:I; 71 return; 72 } 73 } 74 75 // BadStrictSubPreInit is a bad value class that tries to write to an inherited 76 // strict field while acting on UninitializedThis. 77 public final class BadStrictSubPreInit extends StrictBase version 69:65535 { 78 79 public Method "<init>":"()V" stack 2 { 80 aload_0; 81 iconst_1; 82 putfield x:I; 83 aload_0; 84 invokespecial Method StrictBase."<init>":"()V"; 85 return; 86 } 87 } 88 89 // BadStrictSubPostInit is a bad value class that tries to write to an inherited 90 // strict field in "regular" code. 91 public final class BadStrictSubPostInit extends StrictBase version 69:65535 { 92 93 public Method "<init>":"()V" stack 2 { 94 aload_0; 95 invokespecial Method StrictBase."<init>":"()V"; 96 aload_0; 97 iconst_1; 98 putfield x:I; 99 return; 100 } 101 }