harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r449950 - in /incubator/harmony/enhanced/classlib/trunk/modules/logging/src: main/java/java/util/logging/ main/java/org/apache/harmony/logging/internal/nls/ test/java/org/apache/harmony/logging/tests/java/util/logging/
Date Tue, 26 Sep 2006 08:50:18 GMT
Author: pyang
Date: Tue Sep 26 01:50:17 2006
New Revision: 449950

URL: http://svn.apache.org/viewvc?view=rev&rev=449950
Log:
LogManager should try context classloader to load config class if system classloader failed.

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
    incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java?view=diff&rev=449950&r1=449949&r2=449950
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/java/util/logging/LogManager.java
Tue Sep 26 01:50:17 2006
@@ -397,7 +397,16 @@
                     className);
             return clazz.newInstance();
         } catch (Exception e) {
-            return null;
+            try {
+                Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(
+                        className);
+                return clazz.newInstance();
+            } catch (Exception innerE) {
+                //logging.20=Logging configuration class "{0}" failed
+                System.err.println(Messages.getString("logging.20", className));
+                System.err.println(innerE);
+                return null;
+            }
         }
 
     }
@@ -411,8 +420,7 @@
         String configClassName = System.getProperty("java.util.logging.config.class"); //$NON-NLS-1$
         if (null != configClassName) {
             if (null == getInstanceByClass(configClassName)) {
-                throw new RuntimeException("Cannot instantiate " //$NON-NLS-1$
-                        + configClassName);
+                return;
             }
             needInit = false;
         }

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties?view=diff&rev=449950&r1=449949&r2=449950
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/main/java/org/apache/harmony/logging/internal/nls/messages.properties
Tue Sep 26 01:50:17 2006
@@ -33,6 +33,7 @@
 logging.1E=Error message - {0}
 logging.1F=Exception - {0}
 logging.2=The OutputStream parameter is null
+logging.20=Logging configuration class "{0}" failed
 logging.3=The Formatter parameter is null.
 logging.4=The 'level' parameter is null.
 logging.5=Different version - {0}.{1}

Modified: incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java?view=diff&rev=449950&r1=449949&r2=449950
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/LogManagerTest.java
Tue Sep 26 01:50:17 2006
@@ -1038,5 +1038,27 @@
 			super.checkPermission(permission);
 		}
 	}
-
+    
+    /*
+     * Test config class loading
+     * java -Djava.util.logging.config.class=badConfigClassName ClassLoadingTest 
+     */
+    public static class ClassLoadingTest{
+        public static void main(String[] args) {
+            Thread.currentThread().setContextClassLoader(new MockErrorClassLoader());
+            try{
+                LogManager.getLogManager();
+                fail("Should throw mock error");
+            }catch(MockError e){
+            }
+        }
+        static class MockErrorClassLoader extends ClassLoader{
+            public Class<?> loadClass(String name){
+                throw new MockError();
+            }
+        }
+        static class MockError extends Error{
+        }
+    }    
+    
 }



Mime
View raw message