Path: blob/master/test/jdk/java/beans/VetoableChangeSupport/Test4092906.java
41152 views
/*1* Copyright (c) 1998, 2007, 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 409290626* @summary Tests that hasListeners() is not failed across serialization27* @author Graham Hamilton28*/2930import java.beans.PropertyChangeEvent;31import java.beans.PropertyVetoException;32import java.beans.VetoableChangeListener;33import java.beans.VetoableChangeSupport;3435import java.io.ByteArrayInputStream;36import java.io.ByteArrayOutputStream;37import java.io.ObjectInputStream;38import java.io.ObjectOutputStream;39import java.io.Serializable;4041public class Test4092906 {42private static final String PUBLIC = "public";43private static final String PRIVATE = "private";4445public static void main(String[] args) {46VetoableChangeSupport pcs = new VetoableChangeSupport(args);47pcs.addVetoableChangeListener(PUBLIC, new PublicListener());48pcs.addVetoableChangeListener(PRIVATE, new PrivateListener());4950if (!pcs.hasListeners(PUBLIC)) {51throw new Error("no public listener");52}53if (!pcs.hasListeners(PRIVATE)) {54throw new Error("no private listener");55}5657try {58// serialize into byte array59ByteArrayOutputStream baos = new ByteArrayOutputStream();60ObjectOutputStream output = new ObjectOutputStream(baos);61output.writeObject(pcs);62output.flush();63// deserialize from byte array64ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());65ObjectInputStream input = new ObjectInputStream(bais);66pcs = (VetoableChangeSupport) input.readObject();67} catch (Exception exception) {68throw new Error("unexpected exception", exception);69}7071if (!pcs.hasListeners(PUBLIC)) {72throw new Error("no public listener");73}74if (pcs.hasListeners(PRIVATE)) {75throw new Error("unexpected private listener");76}77}7879public static class PublicListener implements VetoableChangeListener, Serializable {80public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {81}82}8384private static class PrivateListener implements VetoableChangeListener {85public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {86}87}88}899091