HADOOP-6396. Fix unhelpful exception message when unable to parse umask (jghoman)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@887472 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3549d30d7e
commit
934deda190
@ -147,6 +147,9 @@ Release 0.21.0 - Unreleased
|
||||
HADOOP-6303. Eclipse .classpath template has outdated jar files and is
|
||||
missing some new ones. (cos)
|
||||
|
||||
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
|
||||
|
@ -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 @@ public FsPermission applyUMask(FsPermission umask) {
|
||||
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 @@ public static FsPermission getUMask(Configuration conf) {
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,11 +157,18 @@ public void testBadUmasks() {
|
||||
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() {
|
||||
|
Loading…
Reference in New Issue
Block a user