Skip to content

Commit c152dc2

Browse files
author
Bhavay Pahuja
committed
handle invalid config value gracefully
1 parent 863a5db commit c152dc2

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

hadoop-tools/hadoop-aws/src/main/java/org/apache/hadoop/fs/s3a/S3AFileSystem.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -592,10 +592,17 @@ public void initialize(URI name, Configuration originalConf)
592592

593593
s3aInternals = createS3AInternals();
594594

595-
s3ObjectStorageClassFilter = Optional.of(conf.getTrimmed(READ_RESTORED_GLACIER_OBJECTS,
596-
DEFAULT_READ_RESTORED_GLACIER_OBJECTS))
597-
.map(String::toUpperCase)
598-
.map(S3ObjectStorageClassFilter::valueOf).get();
595+
try {
596+
s3ObjectStorageClassFilter = Optional.of(conf.getTrimmed(READ_RESTORED_GLACIER_OBJECTS,
597+
DEFAULT_READ_RESTORED_GLACIER_OBJECTS))
598+
.map(String::toUpperCase)
599+
.map(S3ObjectStorageClassFilter::valueOf).get();
600+
} catch (IllegalArgumentException e) {
601+
LOG.warn("Invalid value for the config {} is set. Valid values are:" +
602+
"READ_ALL, SKIP_ALL_GLACIER, READ_RESTORED_GLACIER_OBJECTS. Defaulting to READ_ALL",
603+
READ_RESTORED_GLACIER_OBJECTS);
604+
s3ObjectStorageClassFilter = S3ObjectStorageClassFilter.READ_ALL;
605+
}
599606

600607
// look for encryption data
601608
// DT Bindings may override this

hadoop-tools/hadoop-aws/src/test/java/org/apache/hadoop/fs/s3a/list/ITestS3AReadRestoredGlacierObjects.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,17 @@ protected Configuration createConfiguration() {
104104
return newConf;
105105
}
106106

107+
@Test
108+
public void testConfigWithInvalidValue() throws Throwable {
109+
Assume.assumeTrue(type == Type.GLACIER_AND_DEEP_ARCHIVE);
110+
String invalidValue = "ABCDE";
111+
try (FileSystem fs = createFiles(invalidValue)) {
112+
Assertions.assertThat(
113+
fs.listStatus(methodPath()))
114+
.describedAs("FileStatus List of %s", methodPath()).isNotEmpty();
115+
}
116+
}
117+
107118
@Test
108119
public void testIgnoreGlacierObject() throws Throwable {
109120
Assume.assumeTrue(type == Type.GLACIER_AND_DEEP_ARCHIVE);

0 commit comments

Comments
 (0)