Author: kinow Date: Wed Aug 9 01:50:36 2017 New Revision: 1804480 URL: http://svn.apache.org/viewvc?rev=1804480&view=rev Log: VFS-189: fail with exception if base filename is null
Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileSystemManagerTest.java Modified: commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java?rev=1804480&r1=1804479&r2=1804480&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java (original) +++ commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs2/impl/DefaultFileSystemManager.java Wed Aug 9 01:50:36 2017 @@ -862,8 +862,11 @@ public class DefaultFileSystemManager im public FileName resolveName(final FileName base, final String name, final NameScope scope) throws FileSystemException { + if (base == null) { + throw new FileSystemException("Invalid base filename."); + } final FileName realBase; - if (base != null && VFS.isUriStyle() && base.isFile()) + if (VFS.isUriStyle() && base.isFile()) { realBase = base.getParent(); } Modified: commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileSystemManagerTest.java URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileSystemManagerTest.java?rev=1804480&r1=1804479&r2=1804480&view=diff ============================================================================== --- commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileSystemManagerTest.java (original) +++ commons/proper/vfs/trunk/core/src/test/java/org/apache/commons/vfs2/impl/test/DefaultFileSystemManagerTest.java Wed Aug 9 01:50:36 2017 @@ -18,6 +18,7 @@ package org.apache.commons.vfs2.impl.tes import java.io.File; +import org.apache.commons.vfs2.FileName; import org.apache.commons.vfs2.FileObject; import org.apache.commons.vfs2.FileSystemException; import org.apache.commons.vfs2.VFS; @@ -56,4 +57,16 @@ public class DefaultFileSystemManagerTes final String absolute = new File("/").getAbsoluteFile().toURI().toString(); VFS.getManager().resolveFile((FileObject) null, absolute); } + + /** + * If the base name is {@code null}, the file system manager should fail + * throwing a FileSystemException. + * + * @see VFS-189 + */ + @Test(expected = FileSystemException.class) + public void testResolveFileNameNull() throws FileSystemException + { + VFS.getManager().resolveName((FileName) null, "../"); + } }