1 /* 2 * Copyright (c) 2015, 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 import java.awt.font.TextAttribute; 25 26 /** 27 * @test 28 * @bug 8060027 29 */ 30 public final class ReferenceToNonStaticField 31 extends AbstractTest<ReferenceToNonStaticField.TestValue> { 32 33 public static final class TestValue { 34 35 // reference to static field 36 public TextAttribute font_default = TextAttribute.FONT; 37 public TextAttribute family_default = TextAttribute.FAMILY; 38 public TextAttribute family_set1; // will be set to the same as default 39 public TextAttribute family_set2; // will be set to the same as default 40 public TextAttribute family_set3; // will be set to the same as default 41 42 // primitive small 43 public int int_1_default = 1; 44 public int int_10_default = 10; 45 public int int_10_set1; // will be set to the same as default 46 public int int_10_set2; // will be set to the same as default 47 public int int_10_set3; // will be set to the same as default 48 49 // primitive big 50 public int int_1000_default = 1000; 51 public int int_2000_default = 2000; 52 public int int_2000_set1; // will be set to the same as default 53 public int int_2000_set2; // will be set to the same as default 54 public int int_2000_set3; // will be set to the same as default 55 56 // wrappers 57 public Integer integer_1_default = new Integer(1); 58 public Integer integer_10_default = new Integer(10); 59 public Integer integer_10_set1; // will be set to the same as default 60 public Integer integer_10_set2; // will be set to the same as default 61 public Integer integer_10_set3; // will be set to the same as default 62 TestValue()63 public TestValue() { 64 } 65 TestValue(final Object ignored)66 public TestValue(final Object ignored) { 67 // set some fields to non-default values, so they will be saved 68 family_set1 = family_default; 69 family_set3 = family_default; 70 family_set2 = family_default; 71 int_10_set1 = int_10_default; 72 int_10_set2 = int_10_default; 73 int_10_set3 = int_10_default; 74 int_2000_set1 = int_2000_default; 75 int_2000_set2 = int_2000_default; 76 int_2000_set3 = int_2000_default; 77 integer_10_set1 = integer_10_default; 78 integer_10_set2 = integer_10_default; 79 integer_10_set3 = integer_10_default; 80 } 81 } 82 main(final String[] args)83 public static void main(final String[] args) { 84 new ReferenceToNonStaticField().test(true); 85 } 86 getObject()87 protected TestValue getObject() { 88 return new TestValue(new Object()); 89 } 90 91 @Override validate(final TestValue before,final TestValue after)92 protected void validate(final TestValue before,final TestValue after) { 93 super.validate(before, after); 94 validate(before); 95 validate(after); 96 } 97 validate(final TestValue object)98 private static void validate(final TestValue object) { 99 // reference to static field 100 if (object.font_default != TextAttribute.FONT) { 101 throw new Error("Wrong font_default: " + object.font_default); 102 } 103 if (object.family_default != TextAttribute.FAMILY) { 104 throw new Error("Wrong family_default: " + object.family_default); 105 } 106 if (object.family_set1 != object.family_default) { 107 throw new Error("Wrong family_set1: " + object.family_set1); 108 } 109 if (object.family_set2 != object.family_default) { 110 throw new Error("Wrong family_set2: " + object.family_set2); 111 } 112 if (object.family_set3 != object.family_default) { 113 throw new Error("Wrong family_set3: " + object.family_set3); 114 } 115 // primitive small 116 if (object.int_1_default != 1) { 117 throw new Error("Wrong int_1_default: " + object.int_1_default); 118 } 119 if (object.int_10_default != 10) { 120 throw new Error("Wrong int_10_default: " + object.int_10_default); 121 } 122 if (object.int_10_set1 != object.int_10_default) { 123 throw new Error("Wrong int_10_set1: " + object.int_10_set1); 124 } 125 if (object.int_10_set2 != object.int_10_default) { 126 throw new Error("Wrong int_10_set2: " + object.int_10_set2); 127 } 128 if (object.int_10_set3 != object.int_10_default) { 129 throw new Error("Wrong int_10_set3: " + object.int_10_set3); 130 } 131 // primitive big 132 if (object.int_1000_default != 1000) { 133 throw new Error("Wrong int_1000_default: " + object.int_1000_default); 134 } 135 if (object.int_2000_default != 2000) { 136 throw new Error("Wrong int_2000_default: " + object.int_2000_default); 137 } 138 if (object.int_2000_set1 != object.int_2000_default) { 139 throw new Error("Wrong int_2000_set1: " + object.int_2000_set1); 140 } 141 if (object.int_2000_set2 != object.int_2000_default) { 142 throw new Error("Wrong int_2000_set2: " + object.int_2000_set2); 143 } 144 if (object.int_2000_set3 != object.int_2000_default) { 145 throw new Error("Wrong int_2000_set3: " + object.int_2000_set3); 146 } 147 // wrappers 148 if (!object.integer_1_default.equals(new Integer(1))) { 149 throw new Error("Wrong integer_1_default: " + object.integer_1_default); 150 } 151 if (!object.integer_10_default.equals(new Integer(10))) { 152 throw new Error("Wrong integer_10_default: " + object.integer_10_default); 153 } 154 if (object.integer_10_set1 != object.integer_10_default) { 155 throw new Error("Wrong integer_10_set1: " + object.integer_10_set1); 156 } 157 if (object.integer_10_set2 != object.integer_10_default) { 158 throw new Error("Wrong integer_10_set2: " + object.integer_10_set2); 159 } 160 if (object.integer_10_set3 != object.integer_10_default) { 161 throw new Error("Wrong integer_10_set3: " + object.integer_10_set3); 162 } 163 } 164 } 165