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 2021/11/27 03:27:24 UTC
[commons-vfs] 05/08: Fix PMD EmptyCatchBlock.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-vfs.git
commit e496120c2e5bff03b1d17e8e97ebbe7bb4af5190
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Nov 26 21:38:37 2021 -0500
Fix PMD EmptyCatchBlock.
---
.../provider/hdfs/HdfsFileSystemConfigBuilder.java | 24 +++++-----
.../commons/vfs2/provider/sftp/SftpFileObject.java | 52 +++++++++-------------
.../commons/vfs2/provider/sftp/SftpFileSystem.java | 5 ++-
3 files changed, 37 insertions(+), 44 deletions(-)
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java
index b6ebe7c..4c9a3b3 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/hdfs/HdfsFileSystemConfigBuilder.java
@@ -118,21 +118,21 @@ public final class HdfsFileSystemConfigBuilder extends FileSystemConfigBuilder {
* @see #setConfigURL(FileSystemOptions, URL)
*/
public URL[] getConfigURLs(final FileSystemOptions opts) {
- try {
- final String urlNames = this.getString(opts, KEY_CONFIG_URLS);
- if (StringUtils.isEmpty(urlNames)) {
- return null;
- }
- final String[] urls = urlNames.split(",");
- final URL[] realURLs = new URL[urls.length];
- for (int i = 0; i < urls.length; i++) {
+ final String urlNames = this.getString(opts, KEY_CONFIG_URLS);
+ if (StringUtils.isEmpty(urlNames)) {
+ return null;
+ }
+ final String[] urls = urlNames.split(",");
+ final URL[] realURLs = new URL[urls.length];
+ for (int i = 0; i < urls.length; i++) {
+ try {
realURLs[i] = new URL(urls[i]);
+ } catch (MalformedURLException e) {
+ // This should never happen because we save it in the proper form.
+ throw new IllegalArgumentException(urls[i], e);
}
- return realURLs;
- } catch (final MalformedURLException mue) {
- // This should never happen because we save it in the proper form
}
- return null;
+ return realURLs;
}
/**
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
index 9ef7aa9..c38e6cd 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileObject.java
@@ -157,43 +157,35 @@ public class SftpFileObject extends AbstractFileObject<SftpFileSystem> {
@SuppressWarnings("resource")
@Override
protected InputStream doGetInputStream(final int bufferSize) throws Exception {
- // VFS-113: avoid npe
+ // VFS-113: avoid NPE.
synchronized (getAbstractFileSystem()) {
final ChannelSftp channel = getAbstractFileSystem().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());
- */
+ // return channel.get(getName().getPath());
+ // hmmm - using the in memory method is soooo much faster ...
- final InputStream inputStream;
- try {
- // VFS-210: sftp allows to gather an input stream even from a directory and will
- // fail on first read. So we need to check the type anyway
- if (!getType().hasContent()) {
- throw new FileSystemException("vfs.provider/read-not-file.error", getName());
- }
+ // TODO - Don't read the entire file into memory. Use the
+ // stream-based methods on ChannelSftp once they work properly
- inputStream = channel.get(relPath);
- } catch (final SftpException e) {
- if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
- throw new FileNotFoundException(getName());
- }
+ /*
+ * final ByteArrayOutputStream outstr = new ByteArrayOutputStream(); channel.get(relPath, outstr); outstr.close();
+ * return new ByteArrayInputStream(outstr.toByteArray());
+ */
- throw new FileSystemException(e);
+ final InputStream inputStream;
+ try {
+ // VFS-210: sftp allows to gather an input stream even from a directory and will
+ // fail on first read. So we need to check the type anyway
+ if (!getType().hasContent()) {
+ throw new FileSystemException("vfs.provider/read-not-file.error", getName());
}
-
- return new SftpInputStream(channel, inputStream, bufferSize);
-
- } finally {
- // getAbstractFileSystem().putChannel(channel);
+ inputStream = channel.get(relPath);
+ } catch (final SftpException e) {
+ if (e.id == ChannelSftp.SSH_FX_NO_SUCH_FILE) {
+ throw new FileNotFoundException(getName());
+ }
+ throw new FileSystemException(e);
}
+ return new SftpInputStream(channel, inputStream, bufferSize);
}
}
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
index b652048..9b1a594 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/sftp/SftpFileSystem.java
@@ -178,8 +178,9 @@ public class SftpFileSystem extends AbstractFileSystem {
while (!channel.isClosed()) {
try {
Thread.sleep(SLEEP_MILLIS);
- } catch (final Exception ee) {
- // TODO: swallow exception, really?
+ } catch (InterruptedException e) {
+ // Someone asked us to stop.
+ break;
}
}
} finally {