Author: davsclaus
Date: Tue Nov 10 13:30:57 2009
New Revision: 834460
URL: http://svn.apache.org/viewvc?rev=834460&view=rev
Log:
CAMEL-2153: Fixed potential NPE on some FTP servers.
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java?rev=834460&r1=834459&r2=834460&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/FtpOperations.java
Tue Nov 10 13:30:57 2009
@@ -373,6 +373,10 @@
String onlyName = FileUtil.stripPath(name);
try {
String[] names = client.listNames(directory);
+ // can return either null or an empty list depending on FTP servers
+ if (names == null) {
+ return false;
+ }
for (String existing : names) {
if (existing.equals(onlyName)) {
return true;
@@ -413,7 +417,10 @@
try {
final List<FTPFile> list = new ArrayList<FTPFile>();
FTPFile[] files = client.listFiles(path);
- list.addAll(Arrays.asList(files));
+ // can return either null or an empty list depending on FTP servers
+ if (files != null) {
+ list.addAll(Arrays.asList(files));
+ }
return list;
} catch (IOException e) {
throw new
GenericFileOperationFailedException(client.getReplyCode(),
client.getReplyString(), e.getMessage(), e);
Modified:
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
URL:
http://svn.apache.org/viewvc/camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java?rev=834460&r1=834459&r2=834460&view=diff
==============================================================================
---
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
(original)
+++
camel/trunk/components/camel-ftp/src/main/java/org/apache/camel/component/file/remote/SftpOperations.java
Tue Nov 10 13:30:57 2009
@@ -295,8 +295,11 @@
try {
final List<ChannelSftp.LsEntry> list = new
ArrayList<ChannelSftp.LsEntry>();
Vector files = channel.ls(path);
- for (Object file : files) {
- list.add((ChannelSftp.LsEntry)file);
+ // can return either null or an empty list depending on FTP servers
+ if (files != null) {
+ for (Object file : files) {
+ list.add((ChannelSftp.LsEntry)file);
+ }
}
return list;
} catch (SftpException e) {
@@ -444,6 +447,10 @@
String onlyName = FileUtil.stripPath(name);
try {
Vector files = channel.ls(directory);
+ // can return either null or an empty list depending on FTP servers
+ if (files == null) {
+ return false;
+ }
for (Object file : files) {
ChannelSftp.LsEntry entry = (ChannelSftp.LsEntry) file;
if (entry.getFilename().equals(onlyName)) {