Author: imario Date: Mon Mar 19 12:51:36 2007 New Revision: 520072 URL: http://svn.apache.org/viewvc?view=rev&rev=520072 Log: VFS-113: avoid npe in multithreaded environments
Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java Modified: jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java URL: http://svn.apache.org/viewvc/jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java?view=diff&rev=520072&r1=520071&r2=520072 ============================================================================== --- jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java (original) +++ jakarta/commons/proper/vfs/trunk/core/src/main/java/org/apache/commons/vfs/provider/sftp/SftpFileObject.java Mon Mar 19 12:51:36 2007 @@ -372,23 +372,27 @@ */ protected InputStream doGetInputStream() throws Exception { - final ChannelSftp channel = fileSystem.getChannel(); - try + // VFS-113: avoid npe + synchronized(fileSystem) { - // return channel.get(getName().getPath()); - // hmmm - using the in memory method is soooo much faster ... + final ChannelSftp channel = fileSystem.getChannel(); + try + { + // return channel.get(getName().getPath()); + // hmmm - using the in memory method is soooo much faster ... - // TODO - Don't read the entire file into memory. Use the - // stream-based methods on ChannelSftp once they work properly - final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); - channel.get(relPath, outstr); - outstr.close(); - return new ByteArrayInputStream(outstr.toByteArray()); + // TODO - Don't read the entire file into memory. Use the + // stream-based methods on ChannelSftp once they work properly + final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); + channel.get(relPath, outstr); + outstr.close(); + return new ByteArrayInputStream(outstr.toByteArray()); - } - finally - { - fileSystem.putChannel(channel); + } + finally + { + fileSystem.putChannel(channel); + } } } --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]