Skip to content

Commit 9968157

Browse files
committed
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
1 parent fc07565 commit 9968157

File tree

3 files changed

+26
-10
lines changed

3 files changed

+26
-10
lines changed

CHANGES.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,9 @@ Release 0.21.0 - Unreleased
147147
HADOOP-6303. Eclipse .classpath template has outdated jar files and is
148148
missing some new ones. (cos)
149149

150+
HADOOP-6396. Fix uninformative exception message when unable to parse
151+
umask. (jghoman)
152+
150153
NEW FEATURES
151154

152155
HADOOP-4268. Change fsck to use ClientProtocol methods so that the

src/java/org/apache/hadoop/fs/permission/FsPermission.java

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@
2121
import java.io.DataOutput;
2222
import java.io.IOException;
2323

24-
import org.apache.commons.logging.Log;
25-
import org.apache.commons.logging.LogFactory;
2624
import org.apache.hadoop.conf.Configuration;
2725
import org.apache.hadoop.fs.CommonConfigurationKeys;
2826
import org.apache.hadoop.io.Writable;
@@ -33,8 +31,6 @@
3331
* A class for file/directory permissions.
3432
*/
3533
public class FsPermission implements Writable {
36-
private static final Log LOG = LogFactory.getLog(FsPermission.class);
37-
3834
static final WritableFactory FACTORY = new WritableFactory() {
3935
public Writable newInstance() { return new FsPermission(); }
4036
};
@@ -182,7 +178,8 @@ public FsPermission applyUMask(FsPermission umask) {
182178
otheraction.and(umask.otheraction.not()));
183179
}
184180

185-
/** umask property label Deprecated key may be removed in version .23 */
181+
/** umask property label deprecated key and code in getUMask method
182+
* to accommodate it may be removed in version .23 */
186183
public static final String DEPRECATED_UMASK_LABEL = "dfs.umask";
187184
public static final String UMASK_LABEL =
188185
CommonConfigurationKeys.FS_PERMISSIONS_UMASK_KEY;
@@ -198,10 +195,19 @@ public static FsPermission getUMask(Configuration conf) {
198195
if(conf != null) {
199196
String confUmask = conf.get(UMASK_LABEL);
200197
if(confUmask != null) { // UMASK_LABEL is set
201-
if(conf.deprecatedKeyWasSet(DEPRECATED_UMASK_LABEL))
202-
umask = Integer.parseInt(confUmask); // Evaluate as decimal value
203-
else
204-
umask = new UmaskParser(confUmask).getUMask();
198+
try {
199+
if(conf.deprecatedKeyWasSet(DEPRECATED_UMASK_LABEL))
200+
umask = Integer.parseInt(confUmask); // Evaluate as decimal value
201+
else
202+
umask = new UmaskParser(confUmask).getUMask();
203+
} catch(IllegalArgumentException iae) {
204+
// Provide more explanation for user-facing message
205+
String type = iae instanceof NumberFormatException ? "decimal"
206+
: "octal or symbolic";
207+
208+
throw new IllegalArgumentException("Unable to parse " + confUmask +
209+
" as " + type + " umask.");
210+
}
205211
}
206212
}
207213

src/test/core/org/apache/hadoop/fs/permission/TestFsPermission.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,11 +157,18 @@ public void testBadUmasks() {
157157
FsPermission.getUMask(conf);
158158
fail("Shouldn't have been able to parse bad umask");
159159
} catch(IllegalArgumentException iae) {
160-
assertEquals(iae.getMessage(), b);
160+
assertTrue("Exception should specify parsing error and invalid umask: "
161+
+ iae.getMessage(), isCorrectExceptionMessage(iae.getMessage(), b));
161162
}
162163
}
163164
}
164165

166+
private boolean isCorrectExceptionMessage(String msg, String umask) {
167+
return msg.contains("Unable to parse") &&
168+
msg.contains(umask) &&
169+
msg.contains("octal or symbolic");
170+
}
171+
165172
// Ensure that when the deprecated decimal umask key is used, it is correctly
166173
// parsed as such and converted correctly to an FsPermission value
167174
public void testDeprecatedUmask() {

0 commit comments

Comments
 (0)