You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by te...@apache.org on 2006/08/11 17:23:19 UTC

svn commit: r430805 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/io/FilePermission.java test/java/tests/api/java/io/FilePermissionTest.java

Author: tellison
Date: Fri Aug 11 08:23:19 2006
New Revision: 430805

URL: http://svn.apache.org/viewvc?rev=430805&view=rev
Log:
Fix for HARMONY-1050 ([classlib][io] compatibility: different exception order for new FilePermission(null, "drink"))

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java
    incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java?rev=430805&r1=430804&r2=430805&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/io/FilePermission.java Fri Aug 11 08:23:19 2006
@@ -75,36 +75,34 @@
     }
 
     private void init(final String path, String pathActions) {
-        if (pathActions != null && pathActions != "") { //$NON-NLS-1$
-            if (path != null) {
-                if (path.equals("<<ALL FILES>>")) { //$NON-NLS-1$
-                    includeAll = true;
-                } else {
-                    canonPath = AccessController
-                            .doPrivileged(new PrivilegedAction<String>() {
-                                public String run() {
-                                    try {
-                                        return new File(path)
-                                                .getCanonicalPath();
-                                    } catch (IOException e) {
-                                        return path;
-                                    }
-                                }
-                            });
-                    if (path.equals("*") || path.endsWith(File.separator + "*")) { //$NON-NLS-1$ //$NON-NLS-2$
-                        allDir = true;
-                    }
-                    if (path.equals("-") || path.endsWith(File.separator + "-")) { //$NON-NLS-1$ //$NON-NLS-2$
-                        allSubdir = true;
-                    }
-                }
-                this.actions = toCanonicalActionString(pathActions);
-            } else {
-                throw new NullPointerException(Msg.getString("K006e")); //$NON-NLS-1$
-            }
-        } else {
+        if (pathActions == null || pathActions.equals("")) { //$NON-NLS-1$
             throw new IllegalArgumentException(Msg.getString("K006d")); //$NON-NLS-1$
         }
+        this.actions = toCanonicalActionString(pathActions);
+        
+        if (path == null) {
+            throw new NullPointerException(Msg.getString("K006e")); //$NON-NLS-1$
+        }
+        if (path.equals("<<ALL FILES>>")) { //$NON-NLS-1$
+            includeAll = true;
+        } else {
+            canonPath = AccessController
+                    .doPrivileged(new PrivilegedAction<String>() {
+                        public String run() {
+                            try {
+                                return new File(path).getCanonicalPath();
+                            } catch (IOException e) {
+                                return path;
+                            }
+                        }
+                    });
+            if (path.equals("*") || path.endsWith(File.separator + "*")) { //$NON-NLS-1$ //$NON-NLS-2$
+                allDir = true;
+            }
+            if (path.equals("-") || path.endsWith(File.separator + "-")) { //$NON-NLS-1$ //$NON-NLS-2$
+                allSubdir = true;
+            }
+        }
     }
 
     /**
@@ -166,7 +164,7 @@
             } else if (action.equals("delete")) { //$NON-NLS-1$
                 actionInt |= 1;
             } else {
-                throw new java.lang.IllegalArgumentException(Msg.getString(
+                throw new IllegalArgumentException(Msg.getString(
                         "K006f", action)); //$NON-NLS-1$
             }
             head = tail + 1;

Modified: incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java?rev=430805&r1=430804&r2=430805&view=diff
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java (original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/api/java/io/FilePermissionTest.java Fri Aug 11 08:23:19 2006
@@ -49,6 +49,27 @@
 				"name given to the construcotr did not correspond - construcotr failed",
 				constructFile.getName() == "test constructor");
 
+        // Regression test for HARMONY-1050
+        try {
+            new FilePermission(null, "drink");
+            fail("Expected IAE");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+        
+        try {
+            new FilePermission(null, "read");
+            fail("Expected NPE");
+        } catch (NullPointerException e) {
+            // Expected
+        }
+        
+        try {
+            new FilePermission(null, null);
+            fail("Expected IAE");
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
 	}
 
 	/**