Manish Bansal created VFS-778:
---------------------------------
Summary: SftpFileSystem returning null channel
Key: VFS-778
URL: https://issues.apache.org/jira/browse/VFS-778
Project: Commons VFS
Issue Type: Bug
Affects Versions: 2.6.0, 2.5.0, 2.4.1
Reporter: Manish Bansal
I tested v2.4.1 jar with 8 threads. The purpose was to upload 1.3TB of data on
FTP via sftp protocol. There were 850 folders with varying sizes from 10 MB to
25GB. After the job was finished, It was observed that 50 folders failed to
upload due to null pointer exception as below.
{code:java}
java.lang.NullPointerException: null
at
org.apache.commons.vfs2.provider.sftp.SftpFileObject.doGetOutputStream(SftpFileObject.java:475)
at
org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1239)
at
org.apache.commons.vfs2.provider.DefaultFileContent.buildOutputStream(DefaultFileContent.java:518)
at
org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:404)
at
org.apache.commons.vfs2.provider.DefaultFileContent.getOutputStream(DefaultFileContent.java:392)
at
org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:753)
at
org.apache.commons.vfs2.provider.DefaultFileContent.write(DefaultFileContent.java:771)
at org.apache.commons.vfs2.FileUtil.copyContent(FileUtil.java:37)
at
org.apache.commons.vfs2.provider.AbstractFileObject.copyFrom(AbstractFileObject.java:295)
at com.infy.task.helper.FTPUploader.uploadToFTP(FTPUploader.java:173)
at com.infy.task.helper.FTPUploader.upload(FTPUploader.java:90)
at
com.infy.task.AssetDownloadAndUploadTask.run(AssetDownloadAndUploadTask.java:57)
at
java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at
java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at java.lang.Thread.run(Thread.java:748)
{code}
Further, I have analysed the code, it is very highly likely that it will return
null due to below piece of code.
{code:java}
protected ChannelSftp getChannel() throws IOException {
try {
// Use the pooled channel, or create a new one
ChannelSftp channel = null;
if (idleChannel != null) {
synchronized (this) {
// What will happen if my code comes here and idleChannel is null
if (idleChannel != null) {
channel = idleChannel;
idleChannel = null;
}
}
} else {
channel= .. //create channel
}
// some more code
return channel;
}
{code}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)