Path: blob/master/test/jdk/java/beans/XMLEncoder/ReferenceToNonStaticField.java
41152 views
/*1* Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*/2223import java.awt.font.TextAttribute;2425/**26* @test27* @bug 806002728* @run main/othervm -Djava.security.manager=allow ReferenceToNonStaticField29*/30public final class ReferenceToNonStaticField31extends AbstractTest<ReferenceToNonStaticField.TestValue> {3233public static final class TestValue {3435// reference to static field36public TextAttribute font_default = TextAttribute.FONT;37public TextAttribute family_default = TextAttribute.FAMILY;38public TextAttribute family_set1; // will be set to the same as default39public TextAttribute family_set2; // will be set to the same as default40public TextAttribute family_set3; // will be set to the same as default4142// primitive small43public int int_1_default = 1;44public int int_10_default = 10;45public int int_10_set1; // will be set to the same as default46public int int_10_set2; // will be set to the same as default47public int int_10_set3; // will be set to the same as default4849// primitive big50public int int_1000_default = 1000;51public int int_2000_default = 2000;52public int int_2000_set1; // will be set to the same as default53public int int_2000_set2; // will be set to the same as default54public int int_2000_set3; // will be set to the same as default5556// wrappers57public Integer integer_1_default = new Integer(1);58public Integer integer_10_default = new Integer(10);59public Integer integer_10_set1; // will be set to the same as default60public Integer integer_10_set2; // will be set to the same as default61public Integer integer_10_set3; // will be set to the same as default6263public TestValue() {64}6566public TestValue(final Object ignored) {67// set some fields to non-default values, so they will be saved68family_set1 = family_default;69family_set3 = family_default;70family_set2 = family_default;71int_10_set1 = int_10_default;72int_10_set2 = int_10_default;73int_10_set3 = int_10_default;74int_2000_set1 = int_2000_default;75int_2000_set2 = int_2000_default;76int_2000_set3 = int_2000_default;77integer_10_set1 = integer_10_default;78integer_10_set2 = integer_10_default;79integer_10_set3 = integer_10_default;80}81}8283public static void main(final String[] args) {84new ReferenceToNonStaticField().test(true);85}8687protected TestValue getObject() {88return new TestValue(new Object());89}9091@Override92protected void validate(final TestValue before,final TestValue after) {93super.validate(before, after);94validate(before);95validate(after);96}9798private static void validate(final TestValue object) {99// reference to static field100if (object.font_default != TextAttribute.FONT) {101throw new Error("Wrong font_default: " + object.font_default);102}103if (object.family_default != TextAttribute.FAMILY) {104throw new Error("Wrong family_default: " + object.family_default);105}106if (object.family_set1 != object.family_default) {107throw new Error("Wrong family_set1: " + object.family_set1);108}109if (object.family_set2 != object.family_default) {110throw new Error("Wrong family_set2: " + object.family_set2);111}112if (object.family_set3 != object.family_default) {113throw new Error("Wrong family_set3: " + object.family_set3);114}115// primitive small116if (object.int_1_default != 1) {117throw new Error("Wrong int_1_default: " + object.int_1_default);118}119if (object.int_10_default != 10) {120throw new Error("Wrong int_10_default: " + object.int_10_default);121}122if (object.int_10_set1 != object.int_10_default) {123throw new Error("Wrong int_10_set1: " + object.int_10_set1);124}125if (object.int_10_set2 != object.int_10_default) {126throw new Error("Wrong int_10_set2: " + object.int_10_set2);127}128if (object.int_10_set3 != object.int_10_default) {129throw new Error("Wrong int_10_set3: " + object.int_10_set3);130}131// primitive big132if (object.int_1000_default != 1000) {133throw new Error("Wrong int_1000_default: " + object.int_1000_default);134}135if (object.int_2000_default != 2000) {136throw new Error("Wrong int_2000_default: " + object.int_2000_default);137}138if (object.int_2000_set1 != object.int_2000_default) {139throw new Error("Wrong int_2000_set1: " + object.int_2000_set1);140}141if (object.int_2000_set2 != object.int_2000_default) {142throw new Error("Wrong int_2000_set2: " + object.int_2000_set2);143}144if (object.int_2000_set3 != object.int_2000_default) {145throw new Error("Wrong int_2000_set3: " + object.int_2000_set3);146}147// wrappers148if (!object.integer_1_default.equals(new Integer(1))) {149throw new Error("Wrong integer_1_default: " + object.integer_1_default);150}151if (!object.integer_10_default.equals(new Integer(10))) {152throw new Error("Wrong integer_10_default: " + object.integer_10_default);153}154if (object.integer_10_set1 != object.integer_10_default) {155throw new Error("Wrong integer_10_set1: " + object.integer_10_set1);156}157if (object.integer_10_set2 != object.integer_10_default) {158throw new Error("Wrong integer_10_set2: " + object.integer_10_set2);159}160if (object.integer_10_set3 != object.integer_10_default) {161throw new Error("Wrong integer_10_set3: " + object.integer_10_set3);162}163}164}165166167