869N/A/*
869N/A * Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
869N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
869N/A *
869N/A * This code is free software; you can redistribute it and/or modify it
869N/A * under the terms of the GNU General Public License version 2 only, as
869N/A * published by the Free Software Foundation.
869N/A *
869N/A * This code is distributed in the hope that it will be useful, but WITHOUT
869N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
869N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
869N/A * version 2 for more details (a copy is included in the LICENSE file that
869N/A * accompanied this code).
869N/A *
869N/A * You should have received a copy of the GNU General Public License version
869N/A * 2 along with this work; if not, write to the Free Software Foundation,
869N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
873N/A *
869N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
869N/A * or visit www.oracle.com if you need additional information or have any
869N/A * questions.
869N/A */
3053N/A
869N/A/*
869N/A * @test
0N/A * @bug 4092906
0N/A * @summary Tests that hasListeners() is not failed across serialization
0N/A * @author Graham Hamilton
0N/A */
869N/A
0N/Aimport java.beans.PropertyChangeEvent;
0N/Aimport java.beans.PropertyVetoException;
0N/Aimport java.beans.VetoableChangeListener;
869N/Aimport java.beans.VetoableChangeSupport;
0N/A
869N/Aimport java.io.ByteArrayInputStream;
0N/Aimport java.io.ByteArrayOutputStream;
869N/Aimport java.io.ObjectInputStream;
869N/Aimport java.io.ObjectOutputStream;
869N/Aimport java.io.Serializable;
2624N/A
869N/Apublic class Test4092906 {
48N/A private static final String PUBLIC = "public";
869N/A private static final String PRIVATE = "private";
0N/A
869N/A public static void main(String[] args) {
716N/A VetoableChangeSupport pcs = new VetoableChangeSupport(args);
869N/A pcs.addVetoableChangeListener(PUBLIC, new PublicListener());
1958N/A pcs.addVetoableChangeListener(PRIVATE, new PrivateListener());
1963N/A
2340N/A if (!pcs.hasListeners(PUBLIC)) {
3103N/A throw new Error("no public listener");
3127N/A }
1954N/A if (!pcs.hasListeners(PRIVATE)) {
1954N/A throw new Error("no private listener");
1954N/A }
1954N/A
1954N/A try {
1954N/A // serialize into byte array
1954N/A ByteArrayOutputStream baos = new ByteArrayOutputStream();
1954N/A ObjectOutputStream output = new ObjectOutputStream(baos);
2350N/A output.writeObject(pcs);
1954N/A output.flush();
1954N/A // deserialize from byte array
1954N/A ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
1954N/A ObjectInputStream input = new ObjectInputStream(bais);
0N/A pcs = (VetoableChangeSupport) input.readObject();
0N/A } catch (Exception exception) {
869N/A throw new Error("unexpected exception", exception);
868N/A }
2624N/A
2693N/A if (!pcs.hasListeners(PUBLIC)) {
2042N/A throw new Error("no public listener");
2982N/A }
1007N/A if (pcs.hasListeners(PRIVATE)) {
2980N/A throw new Error("unexpected private listener");
2963N/A }
1503N/A }
2915N/A
869N/A public static class PublicListener implements VetoableChangeListener, Serializable {
2624N/A public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
2624N/A }
0N/A }
2270N/A
2270N/A private static class PrivateListener implements VetoableChangeListener {
2270N/A public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
2270N/A }
2270N/A }
2270N/A}
2270N/A