harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zhouke...@apache.org
Subject svn commit: r935099 - in /harmony/enhanced/java/trunk/classlib/modules/logging/src: main/java/java/util/logging/FileHandler.java test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
Date Sat, 17 Apr 2010 00:23:40 GMT
Author: zhoukevin
Date: Sat Apr 17 00:23:40 2010
New Revision: 935099

URL: http://svn.apache.org/viewvc?rev=935099&view=rev
Log:
When including %t in pattern of FileHandler class and java.io.tmpdir system property is null,
HY throws FileNotFoundException while RI doesn't.\nWhen including %h in pattern of FileHandler
class and user.home system property is null, HY throws FileNotFoundException while RI throws
NullPointerException.

Modified:
    harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/FileHandler.java
    harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java

Modified: harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/FileHandler.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/FileHandler.java?rev=935099&r1=935098&r2=935099&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/FileHandler.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/logging/src/main/java/java/util/logging/FileHandler.java
Sat Apr 17 00:23:40 2010
@@ -277,14 +277,15 @@ public class FileHandler extends StreamH
         boolean hasGeneration = false;
 
         // TODO privilege code?
+        String homePath = System.getProperty("user.home"); //$NON-NLS-1$
+        if (homePath == null) {
+            throw new NullPointerException();
+        }
+        boolean homePathHasSepEnd = homePath.endsWith(File.separator);
 
         String tempPath = System.getProperty("java.io.tmpdir"); //$NON-NLS-1$
-        boolean tempPathHasSepEnd = (tempPath == null ? false : tempPath
-                .endsWith(File.separator));
-
-        String homePath = System.getProperty("user.home"); //$NON-NLS-1$
-        boolean homePathHasSepEnd = (homePath == null ? false : homePath
-                .endsWith(File.separator));
+        tempPath = tempPath == null ? homePath : tempPath;
+        boolean tempPathHasSepEnd = tempPath.endsWith(File.separator);
 
         StringBuilder sb = new StringBuilder();
         pattern = pattern.replace('/', File.separatorChar);

Modified: harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java?rev=935099&r1=935098&r2=935099&view=diff
==============================================================================
--- harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
(original)
+++ harmony/enhanced/java/trunk/classlib/modules/logging/src/test/java/org/apache/harmony/logging/tests/java/util/logging/FileHandlerTest.java
Sat Apr 17 00:23:40 2010
@@ -60,9 +60,13 @@ public class FileHandlerTest extends Tes
 
     final static SecurityManager securityManager = new MockLogSecurityManager();
 
-    final static String HOMEPATH = System.getProperty("user.home");
+    final static String USR_HOME_KEY = "user.home";
 
-    final static String TEMPPATH = System.getProperty("java.io.tmpdir");
+    final static String TMP_DIR_KEY = "java.io.tmpdir";
+
+    final static String HOMEPATH = System.getProperty(USR_HOME_KEY);
+
+    final static String TEMPPATH = System.getProperty(TMP_DIR_KEY);
 
     final static String SEP = File.separator;
 
@@ -125,6 +129,55 @@ public class FileHandlerTest extends Tes
         super.tearDown();
     }
 
+    public void testConstructor_NoUsrHome() throws IOException {
+        System.clearProperty(USR_HOME_KEY);
+
+        try {
+            new FileHandler("%h/log_NoUsrHome.log");
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        } finally {
+            if (HOMEPATH != null) {
+                System.setProperty(USR_HOME_KEY, HOMEPATH);
+            }
+        }
+    }
+
+    public void testConstructor_NoTmpDir() throws IOException {
+        System.clearProperty(TMP_DIR_KEY);
+
+        try {
+            new FileHandler("%t/log_NoTmpDir.log");
+        } finally {
+            if (TEMPPATH != null) {
+                System.setProperty(TMP_DIR_KEY, TEMPPATH);
+            }
+        }
+        assertFalse(new File(TEMPPATH, "log_NoTmpDir.log").exists());
+        assertTrue(new File(HOMEPATH, "log_NoTmpDir.log").exists());
+        new File(HOMEPATH, "log_NoTmpDir.log").delete();
+    }
+
+    public void testConstructor_NoTmpDir_NoUsrHome() throws IOException {
+        System.clearProperty(TMP_DIR_KEY);
+        System.clearProperty(USR_HOME_KEY);
+
+        try {
+            new FileHandler("%t/log_NoTmpDir_NoUsrHome.log");
+            fail("should throw NullPointerException");
+        } catch (NullPointerException e) {
+            // Expected
+        } finally {
+            if (TEMPPATH != null) {
+                System.setProperty(TMP_DIR_KEY, TEMPPATH);
+            }
+            if (HOMEPATH != null) {
+                System.setProperty(USR_HOME_KEY, HOMEPATH);
+            }
+        }
+    }
+
     public void testLock() throws Exception {
         FileOutputStream output = new FileOutputStream(TEMPPATH + SEP + "log"
                 + SEP + "java1.test.0");



Mime
View raw message