Skip to content

Commit 82a1c28

Browse files
committed
HADOOP-9041. FsUrlStreamHandlerFactory could cause an infinite loop in FileSystem initialization. (Yanbo Liang and Radim Kolar via llu)
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1422430 13f79535-47bb-0310-9956-ffa450edef68
1 parent 46a7e02 commit 82a1c28

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FsUrlStreamHandlerFactory.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,12 @@ public FsUrlStreamHandlerFactory() {
5656

5757
public FsUrlStreamHandlerFactory(Configuration conf) {
5858
this.conf = new Configuration(conf);
59+
// force init of FileSystem code to avoid HADOOP-9041
60+
try {
61+
FileSystem.getFileSystemClass("file", conf);
62+
} catch (IOException io) {
63+
throw new RuntimeException(io);
64+
}
5965
this.handler = new FsUrlStreamHandler(this.conf);
6066
}
6167

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/**
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.fs;
19+
20+
import org.apache.hadoop.conf.Configuration;
21+
22+
import java.io.IOException;
23+
import java.net.URL;
24+
25+
import org.junit.Test;
26+
import static org.junit.Assert.*;
27+
28+
public class TestFileSystemInitialization {
29+
30+
/**
31+
* Check if FileSystem can be properly initialized if URLStreamHandlerFactory
32+
* is registered.
33+
*/
34+
@Test
35+
public void testInitializationWithRegisteredStreamFactory() {
36+
Configuration conf = new Configuration();
37+
URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory(conf));
38+
try {
39+
FileSystem.getFileSystemClass("file", conf);
40+
}
41+
catch (IOException ok) {
42+
// we might get an exception but this not related to infinite loop problem
43+
assertFalse(false);
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)