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 2023/06/23 20:27:16 UTC

[commons-vfs] 09/15: [provider] Throw a specialized RuntimeException instead of RuntimeException

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 14426c160549a2f52dafeb7284ad276118b3373c
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Jun 23 16:25:33 2023 -0400

    [provider] Throw a specialized RuntimeException instead of
    RuntimeException
---
 .../java/org/apache/commons/vfs2/provider/AbstractFileObject.java  | 3 ++-
 .../java/org/apache/commons/vfs2/provider/AbstractFileSystem.java  | 7 ++-----
 .../org/apache/commons/vfs2/provider/DefaultURLConnection.java     | 7 ++++---
 .../org/apache/commons/vfs2/provider/DefaultURLStreamHandler.java  | 3 ++-
 4 files changed, 10 insertions(+), 10 deletions(-)

diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
index 68c86f38..eb8981da 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileObject.java
@@ -21,6 +21,7 @@ import java.io.FileNotFoundException;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UncheckedIOException;
 import java.net.URL;
 import java.security.AccessController;
 import java.security.PrivilegedActionException;
@@ -1864,7 +1865,7 @@ public abstract class AbstractFileObject<AFS extends AbstractFileSystem> impleme
             try {
                 fileName.setType(type);
             } catch (final FileSystemException e) {
-                throw new RuntimeException(e.getMessage());
+                throw new UncheckedIOException(e);
             }
         }
         this.type = type;
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
index b42ef2f1..3045b332 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/AbstractFileSystem.java
@@ -23,6 +23,7 @@ import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
 import java.util.Map;
+import java.util.Objects;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicLong;
 
@@ -315,11 +316,7 @@ public abstract class AbstractFileSystem extends AbstractVfsComponent implements
 
     private FilesCache getFilesCache() {
         final FilesCache filesCache = getContext().getFileSystemManager().getFilesCache();
-        if (filesCache == null) {
-            throw new RuntimeException(Messages.getString("vfs.provider/files-cache-missing.error"));
-        }
-
-        return filesCache;
+        return Objects.requireNonNull(filesCache, () -> Messages.getString("vfs.provider/files-cache-missing.error"));
     }
 
     /**
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLConnection.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLConnection.java
index f6deecac..ad10f764 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLConnection.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLConnection.java
@@ -19,6 +19,7 @@ package org.apache.commons.vfs2.provider;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.UncheckedIOException;
 import java.net.URL;
 import java.net.URLConnection;
 
@@ -53,7 +54,7 @@ public final class DefaultURLConnection extends URLConnection {
         try {
             return fileContent.getContentInfo().getContentEncoding();
         } catch (final FileSystemException e) {
-            throw new RuntimeException(e.getMessage());
+            throw new UncheckedIOException(e);
         }
     }
 
@@ -71,7 +72,7 @@ public final class DefaultURLConnection extends URLConnection {
         try {
             return fileContent.getContentInfo().getContentType();
         } catch (final FileSystemException e) {
-            throw new RuntimeException(e.getMessage());
+            throw new UncheckedIOException(e);
         }
     }
 
@@ -99,6 +100,6 @@ public final class DefaultURLConnection extends URLConnection {
      * (content.getFile().getFileSystem().hasCapability(Capability.ATTRIBUTES)) { String value = (String)
      * content.getAttribute(name); if (value != null) { return value; } }
      *
-     * return null; } catch (FileSystemException e) { throw new RuntimeException(e); } }
+     * return null; } catch (FileSystemException e) { throw new UncheckedIOException(e); } }
      */
 }
diff --git a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLStreamHandler.java b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLStreamHandler.java
index 7ef6d93b..41a1b374 100644
--- a/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLStreamHandler.java
+++ b/commons-vfs2/src/main/java/org/apache/commons/vfs2/provider/DefaultURLStreamHandler.java
@@ -17,6 +17,7 @@
 package org.apache.commons.vfs2.provider;
 
 import java.io.IOException;
+import java.io.UncheckedIOException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.net.URLStreamHandler;
@@ -81,7 +82,7 @@ public class DefaultURLStreamHandler extends URLStreamHandler {
             setURL(u, protocolPart, "", -1, null, null, filePart.toString(), null, null);
         } catch (final FileSystemException fse) {
             // This is rethrown to MalformedURLException in URL anyway
-            throw new RuntimeException(fse.getMessage());
+            throw new UncheckedIOException(fse);
         }
     }