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