Skip to content

Commit cbb8580

Browse files
author
Bhavay Pahuja
committed
handle invalid config value gracefully
1 parent df48a67 commit cbb8580

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
@@ -584,10 +584,17 @@ public void initialize(URI name, Configuration originalConf)
584584

585585
s3aInternals = createS3AInternals();
586586

587-
s3ObjectStorageClassFilter = Optional.of(conf.getTrimmed(READ_RESTORED_GLACIER_OBJECTS,
588-
DEFAULT_READ_RESTORED_GLACIER_OBJECTS))
589-
.map(String::toUpperCase)
590-
.map(S3ObjectStorageClassFilter::valueOf).get();
587+
try {
588+
s3ObjectStorageClassFilter = Optional.of(conf.getTrimmed(READ_RESTORED_GLACIER_OBJECTS,
589+
DEFAULT_READ_RESTORED_GLACIER_OBJECTS))
590+
.map(String::toUpperCase)
591+
.map(S3ObjectStorageClassFilter::valueOf).get();
592+
} catch (IllegalArgumentException e) {
593+
LOG.warn("Invalid value for the config {} is set. Valid values are:" +
594+
"READ_ALL, SKIP_ALL_GLACIER, READ_RESTORED_GLACIER_OBJECTS. Defaulting to READ_ALL",
595+
READ_RESTORED_GLACIER_OBJECTS);
596+
s3ObjectStorageClassFilter = S3ObjectStorageClassFilter.READ_ALL;
597+
}
591598

592599
// look for encryption data
593600
// 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)