[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.
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/vfs/trunk@1847065 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
index a88bc82..74966fb 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/ftp/FtpFileObject.java
@@ -157,22 +157,23 @@
* 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 @@
protected void doDetach() {
synchronized (getFileSystem()) {
this.fileInfo = null;
- children = null;
+ this.children = null;
}
}
@@ -280,16 +281,13 @@
if (linkDestination == null) {
final String path;
synchronized (getFileSystem()) {
- path = this.fileInfo.getLink();
+ path = this.fileInfo == null ? null : this.fileInfo.getLink();
}
- FileName relativeTo = getName().getParent();
- if (relativeTo == null) {
- relativeTo = getName();
- }
+ 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 @@
@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 @@
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 @@
@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.
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index a5a16b6..b2482a8 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -107,6 +107,12 @@
<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">