aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Tedor <jason@elastic.co>2016-03-21 10:36:37 -0400
committerJason Tedor <jason@tedor.me>2016-03-21 11:54:05 -0400
commite2ee28348ac179972ae24d0338fd32ac41915821 (patch)
tree5b9d10cc10ca7cd214de6cd1d27363368a9673a1
parent73d95a83b747eb068fd0b123bd17da06d342baf7 (diff)
downloadjimfs-e2ee28348ac179972ae24d0338fd32ac41915821.tar.gz
Throw UOE when setting unsupported attributes
This commit modifies the behavior when setting unsupported attributes to throw an UnsupportedOperationException instead of an IllegalArgumentException. This is to make JimfsFileSystemProvider#createDirectory and JimfsFileSystemProvider#newByteChannel behave consistently with the Javadocs for FileSystemProvider#createDirectory and FileSystemProvider#newByteChannel which require an UnsupportedOperationException to be thrown when the array of attributes contains attributes which can not be set. In particular, these methods are invoked via Files#createTempDirectory and Files#createFile which have the same requirement regarding throwing an UnsupportedOperationException when the array of attributes contains attributes which can not be set. Most notably, this causes a discrepancy between the handling of Jimfs when configured to act like a Windows filesystem versus the behavior of sun.nio.fs.WindowsFileSystem where the former will throw an IllegalArgumentException if an attempt is made to set a POSIX attribute but the latter will throw an UnsupportedOperationException (consistent with the Javadocs).
-rw-r--r--jimfs/src/main/java/com/google/common/jimfs/AttributeService.java2
-rw-r--r--jimfs/src/test/java/com/google/common/jimfs/AttributeServiceTest.java4
-rw-r--r--jimfs/src/test/java/com/google/common/jimfs/JimfsUnixLikeFileSystemTest.java2
3 files changed, 4 insertions, 4 deletions
diff --git a/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java b/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java
index 636066e..9cbe221 100644
--- a/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java
+++ b/jimfs/src/main/java/com/google/common/jimfs/AttributeService.java
@@ -264,7 +264,7 @@ final class AttributeService {
}
}
- throw new IllegalArgumentException("cannot set attribute '" + view + ":" + attribute + "'");
+ throw new UnsupportedOperationException("cannot set attribute '" + view + ":" + attribute + "'");
}
/**
diff --git a/jimfs/src/test/java/com/google/common/jimfs/AttributeServiceTest.java b/jimfs/src/test/java/com/google/common/jimfs/AttributeServiceTest.java
index 8977eda..94b4912 100644
--- a/jimfs/src/test/java/com/google/common/jimfs/AttributeServiceTest.java
+++ b/jimfs/src/test/java/com/google/common/jimfs/AttributeServiceTest.java
@@ -162,14 +162,14 @@ public class AttributeServiceTest {
try {
service.setAttribute(file, "test:blah", "blah", false);
fail();
- } catch (IllegalArgumentException expected) {
+ } catch (UnsupportedOperationException expected) {
}
try {
// baz is defined by "test", but basic doesn't inherit test
service.setAttribute(file, "basic:baz", 5, false);
fail();
- } catch (IllegalArgumentException expected) {
+ } catch (UnsupportedOperationException expected) {
}
assertThat(file.getAttribute("test", "baz")).isEqualTo(1);
diff --git a/jimfs/src/test/java/com/google/common/jimfs/JimfsUnixLikeFileSystemTest.java b/jimfs/src/test/java/com/google/common/jimfs/JimfsUnixLikeFileSystemTest.java
index 72623bd..adb5fb8 100644
--- a/jimfs/src/test/java/com/google/common/jimfs/JimfsUnixLikeFileSystemTest.java
+++ b/jimfs/src/test/java/com/google/common/jimfs/JimfsUnixLikeFileSystemTest.java
@@ -684,7 +684,7 @@ public class JimfsUnixLikeFileSystemTest extends AbstractJimfsIntegrationTest {
try {
Files.createFile(path("/foo"), new BasicFileAttribute<>("basic:noSuchAttribute", "foo"));
fail();
- } catch (IllegalArgumentException expected) {
+ } catch (UnsupportedOperationException expected) {
}
assertThatPath("/foo").doesNotExist();