You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2018/11/20 21:31:02 UTC
svn commit: r1847065 - in /commons/proper/vfs/trunk:
commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
src/changes/changes.xml
Author: ggregory
Date: Tue Nov 20 21:31:02 2018
New Revision: 1847065
URL: http://svn.apache.org/viewvc?rev=1847065&view=rev
Log:
[VFS-294] and [VFS-679].
- [VFS-294] NullPointerException in FtpFileObject.getChildFile() from Johannes Scharf.
- [VFS-679] NullPointerException in FtpFileObject.doGetLastModifiedTime() from Boris Petrov, Gary Gregory.
Modified:
commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
commons/proper/vfs/trunk/src/changes/changes.xml
Modified: commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java?rev=1847065&r1=1847064&r2=1847065&view=diff
==============================================================================
--- commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java (original)
+++ commons/proper/vfs/trunk/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java Tue Nov 20 21:31:02 2018
@@ -157,22 +157,23 @@ public class FtpFileObject extends Abstr
* Fetches the info for this file.
*/
private void getInfo(final boolean flush) throws IOException {
- final FtpFileObject parent = (FtpFileObject) FileObjectUtils.getAbstractFileObject(getParent());
- FTPFile newFileInfo;
- if (parent != null) {
- newFileInfo = parent.getChildFile(UriParser.decode(getName().getBaseName()), flush);
- } else {
- // Assume the root is a directory and exists
- newFileInfo = new FTPFile();
- newFileInfo.setType(FTPFile.DIRECTORY_TYPE);
- }
+ synchronized (getFileSystem()) {
+ final FtpFileObject parent = (FtpFileObject) FileObjectUtils.getAbstractFileObject(getParent());
+ FTPFile newFileInfo;
+ if (parent != null) {
+ newFileInfo = parent.getChildFile(UriParser.decode(getName().getBaseName()), flush);
+ } else {
+ // Assume the root is a directory and exists
+ newFileInfo = new FTPFile();
+ newFileInfo.setType(FTPFile.DIRECTORY_TYPE);
+ }
- if (newFileInfo == null) {
- this.fileInfo = UNKNOWN;
- } else {
- this.fileInfo = newFileInfo;
- }
- }
+ if (newFileInfo == null) {
+ this.fileInfo = UNKNOWN;
+ } else {
+ this.fileInfo = newFileInfo;
+ }
+ }}
/**
* @throws FileSystemException if an error occurs.
@@ -202,7 +203,7 @@ public class FtpFileObject extends Abstr
protected void doDetach() {
synchronized (getFileSystem()) {
this.fileInfo = null;
- children = null;
+ this.children = null;
}
}
@@ -280,16 +281,13 @@ public class FtpFileObject extends Abstr
if (linkDestination == null) {
final String path;
synchronized (getFileSystem()) {
- path = this.fileInfo.getLink();
- }
- FileName relativeTo = getName().getParent();
- if (relativeTo == null) {
- relativeTo = getName();
+ path = this.fileInfo == null ? null : this.fileInfo.getLink();
}
+ final FileName parent = getName().getParent();
+ final FileName relativeTo = parent == null ? getName() : parent;
final FileName linkDestinationName = getFileSystem().getFileSystemManager().resolveName(relativeTo, path);
linkDestination = getFileSystem().resolveFile(linkDestinationName);
}
-
return linkDestination;
}
@@ -372,23 +370,25 @@ public class FtpFileObject extends Abstr
@Override
protected void doDelete() throws Exception {
synchronized (getFileSystem()) {
- final boolean ok;
- final FtpClient ftpClient = getAbstractFileSystem().getClient();
- try {
- if (this.fileInfo.isDirectory()) {
- ok = ftpClient.removeDirectory(relPath);
- } else {
- ok = ftpClient.deleteFile(relPath);
+ if (this.fileInfo != null) {
+ final boolean ok;
+ final FtpClient ftpClient = getAbstractFileSystem().getClient();
+ try {
+ if (this.fileInfo.isDirectory()) {
+ ok = ftpClient.removeDirectory(relPath);
+ } else {
+ ok = ftpClient.deleteFile(relPath);
+ }
+ } finally {
+ getAbstractFileSystem().putClient(ftpClient);
}
- } finally {
- getAbstractFileSystem().putClient(ftpClient);
- }
- if (!ok) {
- throw new FileSystemException("vfs.provider.ftp/delete-file.error", getName());
+ if (!ok) {
+ throw new FileSystemException("vfs.provider.ftp/delete-file.error", getName());
+ }
+ this.fileInfo = null;
}
- this.fileInfo = null;
- children = EMPTY_FTP_FILE_MAP;
+ this.children = EMPTY_FTP_FILE_MAP;
}
}
@@ -412,7 +412,7 @@ public class FtpFileObject extends Abstr
throw new FileSystemException("vfs.provider.ftp/rename-file.error", getName().toString(), newFile);
}
this.fileInfo = null;
- children = EMPTY_FTP_FILE_MAP;
+ this.children = EMPTY_FTP_FILE_MAP;
}
}
@@ -440,6 +440,9 @@ public class FtpFileObject extends Abstr
@Override
protected long doGetContentSize() throws Exception {
synchronized (getFileSystem()) {
+ if (this.fileInfo == null) {
+ return 0;
+ }
if (this.fileInfo.isSymbolicLink()) {
final FileObject linkDest = getLinkDestination();
// VFS-437: Try to avoid a recursion loop.
Modified: commons/proper/vfs/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/vfs/trunk/src/changes/changes.xml?rev=1847065&r1=1847064&r2=1847065&view=diff
==============================================================================
--- commons/proper/vfs/trunk/src/changes/changes.xml (original)
+++ commons/proper/vfs/trunk/src/changes/changes.xml Tue Nov 20 21:31:02 2018
@@ -107,6 +107,12 @@ The <action> type attribute can be add,u
<action issue="VFS-682" dev="ggregory" type="update">
Throw a org.apache.commons.vfs2.FileSystemException instead of a NullPointerException in org.apache.commons.vfs2.impl.DefaultFileSystemManager.resolveName(FileName, String, NameScope).
</action>
+ <action issue="VFS-294" dev="ggregory" type="fix" due-to="Johannes Scharf">
+ NullPointerException in FtpFileObject.getChildFile().
+ </action>
+ <action issue="VFS-679" dev="ggregory" type="fix" due-to="Boris Petrov, Gary Gregory">
+ NullPointerException in FtpFileObject.doGetLastModifiedTime().
+ </action>
</release>
<release version="2.2" date="2017-10-06" description="New features and bug fix release.">
<action issue="VFS-642" dev="pschumacher" type="update" due-to="ilangoldfeld">