Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/java/beans/VetoableChangeSupport/Test4092906.java
41152 views
1
/*
2
* Copyright (c) 1998, 2007, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*/
23
24
/*
25
* @test
26
* @bug 4092906
27
* @summary Tests that hasListeners() is not failed across serialization
28
* @author Graham Hamilton
29
*/
30
31
import java.beans.PropertyChangeEvent;
32
import java.beans.PropertyVetoException;
33
import java.beans.VetoableChangeListener;
34
import java.beans.VetoableChangeSupport;
35
36
import java.io.ByteArrayInputStream;
37
import java.io.ByteArrayOutputStream;
38
import java.io.ObjectInputStream;
39
import java.io.ObjectOutputStream;
40
import java.io.Serializable;
41
42
public class Test4092906 {
43
private static final String PUBLIC = "public";
44
private static final String PRIVATE = "private";
45
46
public static void main(String[] args) {
47
VetoableChangeSupport pcs = new VetoableChangeSupport(args);
48
pcs.addVetoableChangeListener(PUBLIC, new PublicListener());
49
pcs.addVetoableChangeListener(PRIVATE, new PrivateListener());
50
51
if (!pcs.hasListeners(PUBLIC)) {
52
throw new Error("no public listener");
53
}
54
if (!pcs.hasListeners(PRIVATE)) {
55
throw new Error("no private listener");
56
}
57
58
try {
59
// serialize into byte array
60
ByteArrayOutputStream baos = new ByteArrayOutputStream();
61
ObjectOutputStream output = new ObjectOutputStream(baos);
62
output.writeObject(pcs);
63
output.flush();
64
// deserialize from byte array
65
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
66
ObjectInputStream input = new ObjectInputStream(bais);
67
pcs = (VetoableChangeSupport) input.readObject();
68
} catch (Exception exception) {
69
throw new Error("unexpected exception", exception);
70
}
71
72
if (!pcs.hasListeners(PUBLIC)) {
73
throw new Error("no public listener");
74
}
75
if (pcs.hasListeners(PRIVATE)) {
76
throw new Error("unexpected private listener");
77
}
78
}
79
80
public static class PublicListener implements VetoableChangeListener, Serializable {
81
public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
82
}
83
}
84
85
private static class PrivateListener implements VetoableChangeListener {
86
public void vetoableChange(PropertyChangeEvent event) throws PropertyVetoException {
87
}
88
}
89
}
90
91