Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/javax/swing/JFileChooser/4966171/bug4966171.java
41153 views
1
/*
2
* Copyright (c) 2011, 2020, 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
import java.awt.EventQueue;
25
import java.io.ByteArrayInputStream;
26
import java.io.ByteArrayOutputStream;
27
import java.io.ObjectInputStream;
28
import java.io.ObjectOutputStream;
29
import java.util.concurrent.TimeUnit;
30
31
import javax.swing.JFileChooser;
32
import javax.swing.UIManager;
33
import javax.swing.UnsupportedLookAndFeelException;
34
35
import static javax.swing.UIManager.getInstalledLookAndFeels;
36
37
/**
38
* @test
39
* @bug 4966171 8240690
40
* @key headful
41
* @summary Tests that JFileChooser can be serialized
42
*/
43
public final class bug4966171 {
44
45
public static void main(String[] args) throws Exception {
46
for (UIManager.LookAndFeelInfo laf : getInstalledLookAndFeels()) {
47
EventQueue.invokeAndWait(() -> setLookAndFeel(laf));
48
EventQueue.invokeAndWait(bug4966171::test);
49
}
50
}
51
52
private static void test() {
53
// Will run the test no more than 10 seconds per L&F
54
long endtime = System.nanoTime() + TimeUnit.SECONDS.toNanos(10);
55
while (System.nanoTime() < endtime) {
56
try {
57
var byteOut = new ByteArrayOutputStream();
58
try (var out = new ObjectOutputStream(byteOut)) {
59
out.writeObject(new JFileChooser());
60
}
61
var byteIn = new ByteArrayInputStream(byteOut.toByteArray());
62
try (var in = new ObjectInputStream(byteIn)) {
63
JFileChooser readFc = (JFileChooser) in.readObject();
64
}
65
} catch (Throwable e) {
66
throw new RuntimeException(e);
67
}
68
}
69
}
70
71
private static void setLookAndFeel(UIManager.LookAndFeelInfo laf) {
72
try {
73
UIManager.setLookAndFeel(laf.getClassName());
74
} catch (UnsupportedLookAndFeelException ignored) {
75
System.out.println("Unsupported L&F: " + laf.getClassName());
76
} catch (ClassNotFoundException | InstantiationException
77
| IllegalAccessException e) {
78
throw new RuntimeException(e);
79
}
80
}
81
}
82
83