Path: blob/aarch64-shenandoah-jdk8u272-b10/jdk/test/java/beans/Introspector/Test8005065.java
47964 views
/*1* Copyright (c) 2012, 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*/2223/*24* @test25* @bug 800506526* @summary Tests that all arrays in JavaBeans are guarded27* @author Sergey Malenkov28*/2930import java.beans.DefaultPersistenceDelegate;31import java.beans.Encoder;32import java.beans.EventSetDescriptor;33import java.beans.ExceptionListener;34import java.beans.Expression;35import java.beans.Statement;36import java.beans.MethodDescriptor;37import java.beans.ParameterDescriptor;3839public class Test8005065 {4041public static void main(String[] args) {42testDefaultPersistenceDelegate();43testEventSetDescriptor();44testMethodDescriptor();45testStatement();46}4748private static void testDefaultPersistenceDelegate() {49Encoder encoder = new Encoder();50String[] array = { "array" };51MyDPD dpd = new MyDPD(array);52dpd.instantiate(dpd, encoder);53array[0] = null;54dpd.instantiate(dpd, encoder);55}5657private static void testEventSetDescriptor() {58try {59MethodDescriptor[] array = { new MethodDescriptor(MyDPD.class.getMethod("getArray")) };60EventSetDescriptor descriptor = new EventSetDescriptor(null, null, array, null, null);61test(descriptor.getListenerMethodDescriptors());62array[0] = null;63test(descriptor.getListenerMethodDescriptors());64descriptor.getListenerMethodDescriptors()[0] = null;65test(descriptor.getListenerMethodDescriptors());66}67catch (Exception exception) {68throw new Error("unexpected error", exception);69}70}7172private static void testMethodDescriptor() {73try {74ParameterDescriptor[] array = { new ParameterDescriptor() };75MethodDescriptor descriptor = new MethodDescriptor(MyDPD.class.getMethod("getArray"), array);76test(descriptor.getParameterDescriptors());77array[0] = null;78test(descriptor.getParameterDescriptors());79descriptor.getParameterDescriptors()[0] = null;80test(descriptor.getParameterDescriptors());81}82catch (Exception exception) {83throw new Error("unexpected error", exception);84}85}8687private static void testStatement() {88Object[] array = { new Object() };89Statement statement = new Statement(null, null, array);90test(statement.getArguments());91array[0] = null;92test(statement.getArguments());93statement.getArguments()[0] = null;94test(statement.getArguments());95}9697private static <T> void test(T[] array) {98if (array.length != 1) {99throw new Error("unexpected array length");100}101if (array[0] == null) {102throw new Error("unexpected array content");103}104}105106public static class MyDPD107extends DefaultPersistenceDelegate108implements ExceptionListener {109110private final String[] array;111112public MyDPD(String[] array) {113super(array);114this.array = array;115}116117public Expression instantiate(Object instance, Encoder encoder) {118encoder.setExceptionListener(this);119return super.instantiate(instance, encoder);120}121122public String[] getArray() {123return this.array;124}125126public void exceptionThrown(Exception exception) {127throw new Error("unexpected error", exception);128}129}130}131132133