This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git


The following commit(s) were added to refs/heads/master by this push:
     new add1a77  [VFS-739] Changes to parseUri breaks backward compatibility 
by throwing NullPointerException in some cases.
add1a77 is described below

commit add1a771a73c830378eca440f0e7a249c3638faf
Author: Gary Gregory <gardgreg...@gmail.com>
AuthorDate: Mon Oct 7 17:45:27 2019 -0400

    [VFS-739] Changes to parseUri breaks backward compatibility by throwing
    NullPointerException in some cases.
---
 .../vfs2/provider/local/LocalFileNameParser.java   | 12 ++++++-
 .../vfs2/provider/url/UrlFileNameParserTest.java   | 38 ++++++++++++++++++++++
 src/changes/changes.xml                            |  3 ++
 3 files changed, 52 insertions(+), 1 deletion(-)

diff --git 
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
index 3c6be1f..90abfeb 100644
--- 
a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
+++ 
b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/local/LocalFileNameParser.java
@@ -16,8 +16,11 @@
  */
 package org.apache.commons.vfs2.provider.local;
 
+import java.net.URI;
+
 import org.apache.commons.vfs2.FileName;
 import org.apache.commons.vfs2.FileSystemException;
+import org.apache.commons.vfs2.FileSystemManager;
 import org.apache.commons.vfs2.FileType;
 import org.apache.commons.vfs2.VFS;
 import org.apache.commons.vfs2.provider.AbstractFileNameParser;
@@ -63,7 +66,7 @@ public abstract class LocalFileNameParser extends 
AbstractFileNameParser {
         final StringBuilder name = new StringBuilder();
 
         // Extract the scheme
-        String scheme = 
UriParser.extractScheme(context.getFileSystemManager().getSchemes(), uri, name);
+        String scheme = UriParser.extractScheme(getSchemes(context, base, 
uri), uri, name);
         if (scheme == null && base != null) {
             scheme = base.getScheme();
         }
@@ -87,6 +90,13 @@ public abstract class LocalFileNameParser extends 
AbstractFileNameParser {
         return createFileName(scheme, rootFile, path, fileType);
     }
 
+    private String[] getSchemes(final VfsComponentContext context, FileName 
base, String uri) {
+        if (context == null) {
+            return new String[] { base != null ? base.getScheme() : 
URI.create(uri).getScheme() };
+        }
+        return context.getFileSystemManager().getSchemes();
+    }
+
     protected abstract FileName createFileName(String scheme, final String 
rootFile, final String path,
             final FileType type);
 }
diff --git 
a/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java
 
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java
new file mode 100644
index 0000000..6baadda
--- /dev/null
+++ 
b/commons-vfs2/src/test/java/org/apache/commons/vfs2/provider/url/UrlFileNameParserTest.java
@@ -0,0 +1,38 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.vfs2.provider.url;
+
+import java.net.URI;
+
+import org.apache.commons.vfs2.FileName;
+import org.junit.Assert;
+import org.junit.Test;
+
+public class UrlFileNameParserTest {
+
+    @Test
+    public void testJira739() throws Exception {
+        final String uriStr = "maprfs:///";
+        // Check that we have a valid URI
+        final URI uri = new URI(uriStr);
+        // VFS-739 shows that parseUri throws an NPE:
+        final FileName fileName = new UrlFileNameParser().parseUri(null, null, 
uriStr);
+        Assert.assertEquals(uriStr, fileName.getURI());
+        Assert.assertEquals(uri.getScheme(), fileName.getScheme());
+    }
+}
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index f0e3b21..8b39b81 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -95,6 +95,9 @@ The <action> type attribute can be add,update,fix,remove.
       <action issue="VFS-738" dev="ggregory" type="add" due-to="Gary Gregory">
         Deprecate org.apache.commons.vfs2.FileChangeEvent.getFile() in favor 
of getFileObject().
       </action>
+      <action issue="VFS-739" dev="ggregory" type="fix" due-to="xia0c, Gary 
Gregory">
+        Changes to parseUri breaks backward compatibility by throwing 
NullPointerException in some cases.
+      </action>
     </release>
     <release version="2.4.1" date="2019-08-10" description="Bug fix release.">
       <action issue="VFS-725" dev="ggregory" type="fix" due-to="Gary Gregory">

Reply via email to