Skip to content

Commit 7f03025

Browse files
authored
HADOOP-18403. Fix FileSystem leak in ITestS3AAWSCredentialsProvider (#4737)
Contributed By: Viraj Jasani
1 parent b7d4dc6 commit 7f03025

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -162,12 +162,15 @@ public void testAnonymousProvider() throws Exception {
162162
conf.set(AWS_CREDENTIALS_PROVIDER,
163163
AnonymousAWSCredentialsProvider.class.getName());
164164
Path testFile = getCSVTestPath(conf);
165-
FileSystem fs = FileSystem.newInstance(testFile.toUri(), conf);
166-
assertNotNull(fs);
167-
assertTrue(fs instanceof S3AFileSystem);
168-
FileStatus stat = fs.getFileStatus(testFile);
169-
assertNotNull(stat);
170-
assertEquals(testFile, stat.getPath());
165+
try (FileSystem fs = FileSystem.newInstance(testFile.toUri(), conf)) {
166+
assertNotNull("S3AFileSystem instance must not be null", fs);
167+
assertTrue("FileSystem must be the instance of S3AFileSystem", fs instanceof S3AFileSystem);
168+
FileStatus stat = fs.getFileStatus(testFile);
169+
assertNotNull("FileStatus with qualified path must not be null", stat);
170+
assertEquals(
171+
"The qualified path returned by getFileStatus should be same as the original file",
172+
testFile, stat.getPath());
173+
}
171174
}
172175

173176
}

0 commit comments

Comments
 (0)