harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From apetre...@apache.org
Subject svn commit: r519953 - in /harmony/enhanced/classlib/trunk/modules/swing/src: main/java/common/javax/swing/UIDefaults.java test/api/java/common/javax/swing/UIDefaultsTest.java
Date Mon, 19 Mar 2007 14:21:44 GMT
Author: apetrenko
Date: Mon Mar 19 07:21:43 2007
New Revision: 519953

URL: http://svn.apache.org/viewvc?view=rev&rev=519953
Log:
Patch for HARMONY-3420 "[classlib][swing] UIDefaults.ProxyLazyValue.createValue() uses wrong
classloader"

Modified:
    harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java
    harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/UIDefaultsTest.java

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java?view=diff&rev=519953&r1=519952&r2=519953
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/main/java/common/javax/swing/UIDefaults.java
Mon Mar 19 07:21:43 2007
@@ -105,7 +105,8 @@
                 public Object run() {
                     value = null;
                     try {
-                        Class classObj = Class.forName(className);
+                        Class classObj = Class.forName(className, true,
+                                Thread.currentThread().getContextClassLoader());
                         if (params == null) {
                             value = (methodName == null)
                                     ? classObj.newInstance()

Modified: harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/UIDefaultsTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/UIDefaultsTest.java?view=diff&rev=519953&r1=519952&r2=519953
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/UIDefaultsTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/swing/src/test/api/java/common/javax/swing/UIDefaultsTest.java
Mon Mar 19 07:21:43 2007
@@ -177,6 +177,84 @@
         assertNull(uiDefaults.get("4"));
     }
 
+    public void testProxyLazyValueWithThreadClassLoader() throws Exception {
+        // Regression test for HARMONY-3420
+
+        class ArrayClassLoader extends ClassLoader {
+            byte[] bytesMyLabelUI= new byte[] {
+                    /*
+                     * public class MyLabelUI extends LabelUI {
+                     *     public static ComponentUI createUI(JComponent c) {
+                     *         return new MyLabelUI();
+                     *     }
+                     * }
+                     */
+                    -54, -2, -70, -66, 0, 0, 0, 49, 0, 16, 10, 0, 4, 0, 13, 7,
+                    0, 14, 10, 0, 2, 0, 13, 7, 0, 15, 1, 0, 6, 60, 105, 110,
+                    105, 116, 62, 1, 0, 3, 40, 41, 86, 1, 0, 4, 67, 111, 100,
+                    101, 1, 0, 15, 76, 105, 110, 101, 78, 117, 109, 98, 101,
+                    114, 84, 97, 98, 108, 101, 1, 0, 8, 99, 114, 101, 97, 116,
+                    101, 85, 73, 1, 0, 56, 40, 76, 106, 97, 118, 97, 120, 47,
+                    115, 119, 105, 110, 103, 47, 74, 67, 111, 109, 112, 111,
+                    110, 101, 110, 116, 59, 41, 76, 106, 97, 118, 97, 120, 47,
+                    115, 119, 105, 110, 103, 47, 112, 108, 97, 102, 47, 67,
+                    111, 109, 112, 111, 110, 101, 110, 116, 85, 73, 59, 1, 0,
+                    10, 83, 111, 117, 114, 99, 101, 70, 105, 108, 101, 1, 0,
+                    14, 77, 121, 76, 97, 98, 101, 108, 85, 73, 46, 106, 97,
+                    118, 97, 12, 0, 5, 0, 6, 1, 0, 9, 77, 121, 76, 97, 98, 101,
+                    108, 85, 73, 1, 0, 24, 106, 97, 118, 97, 120, 47, 115, 119,
+                    105, 110, 103, 47, 112, 108, 97, 102, 47, 76, 97, 98, 101,
+                    108, 85, 73, 0, 33, 0, 2, 0, 4, 0, 0, 0, 0, 0, 2, 0, 1, 0,
+                    5, 0, 6, 0, 1, 0, 7, 0, 0, 0, 29, 0, 1, 0, 1, 0, 0, 0, 5,
+                    42, -73, 0, 1, -79, 0, 0, 0, 1, 0, 8, 0, 0, 0, 6, 0, 1, 0,
+                    0, 0, 5, 0, 9, 0, 9, 0, 10, 0, 1, 0, 7, 0, 0, 0, 32, 0, 2,
+                    0, 1, 0, 0, 0, 8, -69, 0, 2, 89, -73, 0, 3, -80, 0, 0, 0,
+                    1, 0, 8, 0, 0, 0, 6, 0, 1, 0, 0, 0, 7, 0, 1, 0, 11, 0, 0,
+                    0, 2, 0, 12
+            };
+
+            protected Class findClass(String name) throws ClassNotFoundException {
+                if ("MyLabelUI".equals(name)) {
+                    return defineClass(name, bytesMyLabelUI, 0, bytesMyLabelUI.length);
+                }
+                throw new ClassNotFoundException(name);
+            }
+        };
+
+        final ClassLoader classLoader = new ArrayClassLoader();
+
+        class ThreadGetUIClass extends Thread {
+            private UIDefaults.ProxyLazyValue plv =
+                    new UIDefaults.ProxyLazyValue("MyLabelUI");
+            private Object result;
+
+            public ThreadGetUIClass() {
+                setContextClassLoader(classLoader);
+            }
+
+            public void run() {
+                result = plv.createValue(null);
+            }
+
+            public Object getResult() {
+                while (true) {
+                    try {
+                        join();
+                        return result;
+                    } catch (InterruptedException e) {
+                        // Ignored.
+                    }
+                }
+            }
+        };
+
+        ThreadGetUIClass thread = new ThreadGetUIClass();
+        thread.start();
+        Object result = thread.getResult();
+        assertNotNull(result);
+        assertEquals(result.getClass(), classLoader.loadClass("MyLabelUI"));
+    }
+
     public void testGetUI() {
         setBasicLF();
         final String uiClassName = "javax.swing.plaf.basic.BasicButtonUI";



Mime
View raw message