diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java index 538f03a1300a3..1dd094ec97db0 100644 --- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/viewfs/ViewFileSystem.java @@ -314,7 +314,9 @@ public void initialize(final URI theUri, final Configuration conf) tableName = theUri.getHost(); } try { - myUri = new URI(getScheme(), authority, "/", null, null); + myUri = (authority != null) ? + new URI(getScheme(), authority, null, null, null) : + new URI(getScheme(), null, "/", null, null); boolean initingUriAsFallbackOnNoMounts = supportAutoAddingFallbackOnNoMounts(); fsState = new InodeTree(conf, tableName, myUri, diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java index 877c2228c1eea..b28a416d16d33 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/TestViewFileSystemWithAuthorityLocalFileSystem.java @@ -52,7 +52,7 @@ public void setUp() throws Exception { // Now create a viewfs using a mount table called "default" // hence viewfs://default/ schemeWithAuthority = - new URI(FsConstants.VIEWFS_SCHEME, "default", "/", null, null); + new URI(FsConstants.VIEWFS_SCHEME, "default", null, null, null); fsView = FileSystem.get(schemeWithAuthority, conf); } diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java index 434eff0bef32e..8a3b67a04bf23 100644 --- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java +++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/viewfs/ViewFileSystemBaseTest.java @@ -1515,4 +1515,17 @@ public void testTargetFileSystemLazyInitializationForChecksumMethods() // viewfs inner cache is disabled assertEquals(cacheSize + 1, TestFileUtil.getCacheSize()); } + + @Test + public void testGetURI() throws Exception { + // test that URIs without authority return the path component. + URI viewFsWithoutAuthority = URI.create("viewfs:///"); + FileSystem fs = FileSystem.get(viewFsWithoutAuthority, conf); + assertEquals(viewFsWithoutAuthority, fs.getUri()); + + // test that URIs with authority do not return the path component. + URI viewFsWithAuthority = URI.create("viewfs://default"); + fs = FileSystem.get(viewFsWithAuthority, conf); + assertEquals(viewFsWithAuthority, fs.getUri()); + } }