diff --git a/cadc-util-fs/src/main/java/org/opencadc/util/fs/XAttrCommandExecutor.java b/cadc-util-fs/src/main/java/org/opencadc/util/fs/XAttrCommandExecutor.java index 24e280df..acfa05d2 100644 --- a/cadc-util-fs/src/main/java/org/opencadc/util/fs/XAttrCommandExecutor.java +++ b/cadc-util-fs/src/main/java/org/opencadc/util/fs/XAttrCommandExecutor.java @@ -148,12 +148,17 @@ public static String get(final Path path, final String attributeKey) throws IOEx // getfattr command returns the full attribute in key=value format. final String commandOutput = XAttrCommandExecutor.execute(command); - final Matcher commandOutputMatcher = XAttrCommandExecutor.GET_COMMAND_OUTPUT_PATTERN.matcher(commandOutput); - if (!commandOutputMatcher.find()) { - throw new IllegalStateException("Unknown command output: " + commandOutput); + if (commandOutput == null) { + return null; } else { - return commandOutputMatcher.group(1); + final Matcher commandOutputMatcher = XAttrCommandExecutor.GET_COMMAND_OUTPUT_PATTERN.matcher(commandOutput); + + if (!commandOutputMatcher.find()) { + throw new IllegalStateException("Unknown command output: " + commandOutput); + } else { + return commandOutputMatcher.group(1); + } } } diff --git a/cadc-util-fs/src/test/java/org/opencadc/util/fs/XAttrCommandExecutorTest.java b/cadc-util-fs/src/test/java/org/opencadc/util/fs/XAttrCommandExecutorTest.java index 1f1ec28d..8d8a277e 100644 --- a/cadc-util-fs/src/test/java/org/opencadc/util/fs/XAttrCommandExecutorTest.java +++ b/cadc-util-fs/src/test/java/org/opencadc/util/fs/XAttrCommandExecutorTest.java @@ -108,12 +108,8 @@ public void setAndGetUserAttribute() throws Exception { final Path target = fs.getPath(XAttrCommandExecutorTest.ROOT, folderName).toAbsolutePath(); Files.createDirectory(target); - try { - XAttrCommandExecutor.get(target, "user.foo"); - Assert.fail("Should not already have user.foo attribute."); - } catch (IOException ioException) { - // Good - } + Assert.assertNull("Should not already have user.foo attribute.", + XAttrCommandExecutor.get(target, "user.foo")); XAttrCommandExecutor.set(target, "user.foo", "bar"); @@ -141,14 +137,15 @@ public void setAttributeNullKey() throws Exception { XAttrCommandExecutor.set(target, null, "bogusValue"); } - @Test(expected = IOException.class) + @Test public void getAttributeNoSuchKey() throws Exception { final String folderName = "getAttributeFail-" + UUID.randomUUID(); final FileSystem fs = FileSystems.getDefault(); final Path target = fs.getPath(XAttrCommandExecutorTest.ROOT, folderName).toAbsolutePath(); Files.createDirectory(target); - XAttrCommandExecutor.get(target, "user.bogus.attr"); + Assert.assertNull("Should be null for no such attribute.", + XAttrCommandExecutor.get(target, "user.bogus.attr")); } @Test(expected = IllegalArgumentException.class)