hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jgho...@apache.org
Subject svn commit: r887474 - in /hadoop/common/branches/branch-0.21: CHANGES.txt src/java/org/apache/hadoop/fs/permission/FsPermission.java src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java
Date Sat, 05 Dec 2009 01:00:59 GMT
Author: jghoman
Date: Sat Dec  5 01:00:57 2009
New Revision: 887474

URL: http://svn.apache.org/viewvc?rev=887474&view=rev
Log:
HADOOP-6396.  Fix unhelpful exception message when unable to parse umask (jghoman)

Modified:
    hadoop/common/branches/branch-0.21/CHANGES.txt
    hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/permission/FsPermission.java
    hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java

Modified: hadoop/common/branches/branch-0.21/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/CHANGES.txt?rev=887474&r1=887473&r2=887474&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.21/CHANGES.txt Sat Dec  5 01:00:57 2009
@@ -85,6 +85,9 @@
     and suggests using -skpTrash, when moving to trash fails.
     (Boris Shkolnik via suresh)
 
+    HADOOP-6396. Fix uninformative exception message when unable to parse
+    umask (jghoman)
+
   NEW FEATURES
 
     HADOOP-4268. Change fsck to use ClientProtocol methods so that the

Modified: hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/permission/FsPermission.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/permission/FsPermission.java?rev=887474&r1=887473&r2=887474&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/permission/FsPermission.java
(original)
+++ hadoop/common/branches/branch-0.21/src/java/org/apache/hadoop/fs/permission/FsPermission.java
Sat Dec  5 01:00:57 2009
@@ -21,8 +21,6 @@
 import java.io.DataOutput;
 import java.io.IOException;
 
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.CommonConfigurationKeys;
 import org.apache.hadoop.io.Writable;
@@ -33,8 +31,6 @@
  * A class for file/directory permissions.
  */
 public class FsPermission implements Writable {
-  private static final Log LOG = LogFactory.getLog(FsPermission.class);
-  
   static final WritableFactory FACTORY = new WritableFactory() {
     public Writable newInstance() { return new FsPermission(); }
   };
@@ -182,7 +178,8 @@
         otheraction.and(umask.otheraction.not()));
   }
 
-  /** umask property label Deprecated key may be removed in version .23 */
+  /** umask property label deprecated key and code in getUMask method
+   *  to accommodate it may be removed in version .23 */
   public static final String DEPRECATED_UMASK_LABEL = "dfs.umask"; 
   public static final String UMASK_LABEL = 
                   CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY;
@@ -198,10 +195,19 @@
     if(conf != null) {
       String confUmask = conf.get(UMASK_LABEL);
       if(confUmask != null) { // UMASK_LABEL is set
-        if(conf.deprecatedKeyWasSet(DEPRECATED_UMASK_LABEL)) 
-          umask = Integer.parseInt(confUmask); // Evaluate as decimal value
-        else
-          umask = new UmaskParser(confUmask).getUMask();
+        try {
+          if(conf.deprecatedKeyWasSet(DEPRECATED_UMASK_LABEL)) 
+            umask = Integer.parseInt(confUmask); // Evaluate as decimal value
+          else
+            umask = new UmaskParser(confUmask).getUMask();
+        } catch(IllegalArgumentException iae) {
+          // Provide more explanation for user-facing message
+          String type = iae instanceof NumberFormatException ? "decimal" 
+                                                          : "octal or symbolic";
+          
+          throw new IllegalArgumentException("Unable to parse " + confUmask + 
+                                              " as " + type + " umask.");
+        }
       } 
     }
     

Modified: hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java?rev=887474&r1=887473&r2=887474&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java
(original)
+++ hadoop/common/branches/branch-0.21/src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java
Sat Dec  5 01:00:57 2009
@@ -157,11 +157,18 @@
         FsPermission.getUMask(conf);
         fail("Shouldn't have been able to parse bad umask");
       } catch(IllegalArgumentException iae) {
-        assertEquals(iae.getMessage(), b);
+        assertTrue("Exception should specify parsing error and invalid umask: " 
+            + iae.getMessage(), isCorrectExceptionMessage(iae.getMessage(), b));
       }
     }
   }
   
+  private boolean isCorrectExceptionMessage(String msg, String umask) {
+    return msg.contains("Unable to parse") &&
+           msg.contains(umask) &&
+           msg.contains("octal or symbolic");
+  }
+  
   // Ensure that when the deprecated decimal umask key is used, it is correctly
   // parsed as such and converted correctly to an FsPermission value
   public void testDeprecatedUmask() {



Mime
View raw message