summaryrefslogtreecommitdiff
path: root/java/openjdk6/files/icedtea/openjdk/6669869-queries_per_appcontext.patch
blob: 5e0f001e7b35b7de603bbe4d74b15c394c0feb14 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
# HG changeset patch
# User andrew
# Date 1365686276 -3600
# Node ID a939f541de9af5ccb78225c27cd46cd7dc6bcf87
# Parent  9745a1f43592582cce60d8632d614fafc7dfdc3c
6669869: Beans.isDesignTime() and other queries should be per-AppContext
Reviewed-by: peterz, rupashka

diff --git a/src/share/classes/java/beans/Beans.java b/src/share/classes/java/beans/Beans.java
--- jdk/src/share/classes/java/beans/Beans.java
+++ jdk/src/share/classes/java/beans/Beans.java
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1996, 2006, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1996, 2009, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -27,26 +27,41 @@
 
 import com.sun.beans.finder.ClassFinder;
 
-import java.applet.*;
+import java.applet.Applet;
+import java.applet.AppletContext;
+import java.applet.AppletStub;
+import java.applet.AudioClip;
 
-import java.awt.*;
-
-import java.beans.AppletInitializer;
+import java.awt.GraphicsEnvironment;
+import java.awt.Image;
 
 import java.beans.beancontext.BeanContext;
 
-import java.io.*;
-
-import java.lang.reflect.Constructor;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.ObjectInputStream;
+import java.io.ObjectStreamClass;
+import java.io.StreamCorruptedException;
 
 import java.net.URL;
-import java.lang.reflect.Array;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+import java.util.Enumeration;
+import java.util.Hashtable;
+import java.util.Iterator;
+import java.util.Vector;
+
+import sun.awt.AppContext;
 
 /**
  * This class provides some general purpose beans control methods.
  */
 
 public class Beans {
+    private static final Object DESIGN_TIME = new Object();
+    private static final Object GUI_AVAILABLE = new Object();
 
     /**
      * <p>
@@ -59,12 +74,12 @@
      * @param     beanName    the name of the bean within the class-loader.
      *                        For example "sun.beanbox.foobah"
      *
-     * @exception java.lang.ClassNotFoundException if the class of a serialized
+     * @exception ClassNotFoundException if the class of a serialized
      *              object could not be found.
-     * @exception java.io.IOException if an I/O error occurs.
+     * @exception IOException if an I/O error occurs.
      */
 
-    public static Object instantiate(ClassLoader cls, String beanName) throws java.io.IOException, ClassNotFoundException {
+    public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException {
         return Beans.instantiate(cls, beanName, null, null);
     }
 
@@ -80,12 +95,12 @@
      *                        For example "sun.beanbox.foobah"
      * @param     beanContext The BeanContext in which to nest the new bean
      *
-     * @exception java.lang.ClassNotFoundException if the class of a serialized
+     * @exception ClassNotFoundException if the class of a serialized
      *              object could not be found.
-     * @exception java.io.IOException if an I/O error occurs.
+     * @exception IOException if an I/O error occurs.
      */
 
-    public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws java.io.IOException, ClassNotFoundException {
+    public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException {
         return Beans.instantiate(cls, beanName, beanContext, null);
     }
 
@@ -135,19 +150,19 @@
      * @param     beanContext The BeanContext in which to nest the new bean
      * @param     initializer The AppletInitializer for the new bean
      *
-     * @exception java.lang.ClassNotFoundException if the class of a serialized
+     * @exception ClassNotFoundException if the class of a serialized
      *              object could not be found.
-     * @exception java.io.IOException if an I/O error occurs.
+     * @exception IOException if an I/O error occurs.
      */
 
     public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer)
-                        throws java.io.IOException, ClassNotFoundException {
+                        throws IOException, ClassNotFoundException {
 
-        java.io.InputStream ins;
-        java.io.ObjectInputStream oins = null;
+        InputStream ins;
+        ObjectInputStream oins = null;
         Object result = null;
         boolean serialized = false;
-        java.io.IOException serex = null;
+        IOException serex = null;
 
         // If the given classloader is null, we check if an
         // system classloader is available and (if so)
@@ -166,8 +181,8 @@
         // Try to find a serialized object with this name
         final String serName = beanName.replace('.','/').concat(".ser");
         final ClassLoader loader = cls;
-        ins = (InputStream)java.security.AccessController.doPrivileged
-            (new java.security.PrivilegedAction() {
+        ins = (InputStream)AccessController.doPrivileged
+            (new PrivilegedAction() {
                 public Object run() {
                     if (loader == null)
                         return ClassLoader.getSystemResourceAsStream(serName);
@@ -185,7 +200,7 @@
                 result = oins.readObject();
                 serialized = true;
                 oins.close();
-            } catch (java.io.IOException ex) {
+            } catch (IOException ex) {
                 ins.close();
                 // Drop through and try opening the class.  But remember
                 // the exception in case we can't find the class either.
@@ -264,8 +279,8 @@
 
                     final ClassLoader cloader = cls;
                     objectUrl = (URL)
-                        java.security.AccessController.doPrivileged
-                        (new java.security.PrivilegedAction() {
+                        AccessController.doPrivileged
+                        (new PrivilegedAction() {
                             public Object run() {
                                 if (cloader == null)
                                     return ClassLoader.getSystemResource
@@ -377,10 +392,11 @@
      * @return  True if we are running in an application construction
      *          environment.
      *
-     * @see java.beans.DesignMode
+     * @see DesignMode
      */
     public static boolean isDesignTime() {
-        return designTime;
+        Object value = AppContext.getAppContext().get(DESIGN_TIME);
+        return (value instanceof Boolean) && (Boolean) value;
     }
 
     /**
@@ -393,11 +409,12 @@
      *     false in a server environment or if an application is
      *     running as part of a batch job.
      *
-     * @see java.beans.Visibility
+     * @see Visibility
      *
      */
     public static boolean isGuiAvailable() {
-        return guiAvailable;
+        Object value = AppContext.getAppContext().get(GUI_AVAILABLE);
+        return (value instanceof Boolean) ? (Boolean) value : !GraphicsEnvironment.isHeadless();
     }
 
     /**
@@ -423,7 +440,7 @@
         if (sm != null) {
             sm.checkPropertiesAccess();
         }
-        designTime = isDesignTime;
+        AppContext.getAppContext().put(DESIGN_TIME, Boolean.valueOf(isDesignTime));
     }
 
     /**
@@ -449,14 +466,7 @@
         if (sm != null) {
             sm.checkPropertiesAccess();
         }
-        guiAvailable = isGuiAvailable;
-    }
-
-
-    private static boolean designTime;
-    private static boolean guiAvailable;
-    static {
-        guiAvailable = !GraphicsEnvironment.isHeadless();
+        AppContext.getAppContext().put(GUI_AVAILABLE, Boolean.valueOf(isGuiAvailable));
     }
 }
 
@@ -501,7 +511,7 @@
 
 class BeansAppletContext implements AppletContext {
     Applet target;
-    java.util.Hashtable imageCache = new java.util.Hashtable();
+    Hashtable imageCache = new Hashtable();
 
     BeansAppletContext(Applet target) {
         this.target = target;
@@ -546,8 +556,8 @@
         return null;
     }
 
-    public java.util.Enumeration getApplets() {
-        java.util.Vector applets = new java.util.Vector();
+    public Enumeration getApplets() {
+        Vector applets = new Vector();
         applets.addElement(target);
         return applets.elements();
     }
@@ -573,7 +583,7 @@
         return null;
     }
 
-    public java.util.Iterator getStreamKeys(){
+    public Iterator getStreamKeys(){
         // We do nothing.
         return null;
     }
diff --git a/test/java/beans/Beans/6669869/TestDesignTime.java b/test/java/beans/Beans/6669869/TestDesignTime.java
new file mode 100644
--- /dev/null
+++ jdk/test/java/beans/Beans/6669869/TestDesignTime.java
@@ -0,0 +1,52 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6669869
+ * @summary Tests DesignTime property in different application contexts
+ * @author Sergey Malenkov
+ */
+
+import java.beans.Beans;
+import sun.awt.SunToolkit;
+
+public class TestDesignTime implements Runnable {
+    public static void main(String[] args) throws InterruptedException {
+        if (Beans.isDesignTime()) {
+            throw new Error("unexpected DesignTime property");
+        }
+        Beans.setDesignTime(!Beans.isDesignTime());
+        ThreadGroup group = new ThreadGroup("$$$");
+        Thread thread = new Thread(group, new TestDesignTime());
+        thread.start();
+        thread.join();
+    }
+
+    public void run() {
+        SunToolkit.createNewAppContext();
+        if (Beans.isDesignTime()) {
+            throw new Error("shared DesignTime property");
+        }
+    }
+}
diff --git a/test/java/beans/Beans/6669869/TestGuiAvailable.java b/test/java/beans/Beans/6669869/TestGuiAvailable.java
new file mode 100644
--- /dev/null
+++ jdk/test/java/beans/Beans/6669869/TestGuiAvailable.java
@@ -0,0 +1,53 @@
+/*
+ * Copyright 2009 Sun Microsystems, Inc.  All Rights Reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ * CA 95054 USA or visit www.sun.com if you need additional information or
+ * have any questions.
+ */
+
+/*
+ * @test
+ * @bug 6669869
+ * @summary Tests GuiAvailable property in different application contexts
+ * @author Sergey Malenkov
+ */
+
+import java.awt.GraphicsEnvironment;
+import java.beans.Beans;
+import sun.awt.SunToolkit;
+
+public class TestGuiAvailable implements Runnable {
+    public static void main(String[] args) throws InterruptedException {
+        if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
+            throw new Error("unexpected GuiAvailable property");
+        }
+        Beans.setGuiAvailable(!Beans.isGuiAvailable());
+        ThreadGroup group = new ThreadGroup("$$$");
+        Thread thread = new Thread(group, new TestGuiAvailable());
+        thread.start();
+        thread.join();
+    }
+
+    public void run() {
+        SunToolkit.createNewAppContext();
+        if (Beans.isGuiAvailable() == GraphicsEnvironment.isHeadless()) {
+            throw new Error("shared GuiAvailable property");
+        }
+    }
+}