Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2020-10-30 19:16:20 +0000
committerThomas Watson2020-10-30 19:16:47 +0000
commit11fa29c9a6e86962b9414dca448b87f929228653 (patch)
tree82a56453f9b236f4eb6200de9910ae84688f9bd7
parent5f935ae7f99c9cfac59a3f4af55bbd0da26a7238 (diff)
downloadrt.equinox.framework-I20201114-1800.tar.gz
rt.equinox.framework-I20201114-1800.tar.xz
rt.equinox.framework-I20201114-1800.zip
Some environments it is more costly to do the file open/close operation than simply calling Files.isReadable. First try Files.isReadable for the golden path, if that fails then fallback to the previous behavior Change-Id: I7aaf92c4d3d1a599343034078ebb214a8da7a305 Signed-off-by: Thomas Watson <tjwatson@us.ibm.com>
-rw-r--r--bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java45
1 files changed, 25 insertions, 20 deletions
diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java
index d6b653f55..08de673ad 100644
--- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java
+++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/storage/url/reference/ReferenceURLConnection.java
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
+import java.nio.file.Files;
import org.eclipse.osgi.framework.util.FilePath;
import org.eclipse.osgi.internal.location.LocationHelper;
import org.eclipse.osgi.internal.messages.Msg;
@@ -69,26 +70,30 @@ public class ReferenceURLConnection extends URLConnection {
private void checkRead(File file) throws IOException {
if (!file.exists())
throw new FileNotFoundException(file.toString());
- if (file.isFile()) {
- // Try to open the file to ensure that this is possible: see bug 260217
- // If access is denied, a FileNotFoundException with (access denied) message is thrown
- // Here file.canRead() cannot be used, because on Windows it does not
- // return correct values - bug 6203387 in Sun's bug database
- InputStream is = new FileInputStream(file);
- is.close();
- } else if (file.isDirectory()) {
- // There is no straightforward way to check if a directory
- // has read permissions - same issues for File.canRead() as above;
- // try to list the files in the directory
- File[] files = file.listFiles();
- // File.listFiles() returns null if the directory does not exist
- // (which is not the current case, because we check that it exists and is directory),
- // or if an IO error occurred during the listing of the files, including if the
- // access is denied
- if (files == null)
- throw new FileNotFoundException(file.toString() + " (probably access denied)"); //$NON-NLS-1$
- } else {
- // TODO not sure if we can get here.
+ if (!Files.isReadable(file.toPath())) {
+ if (file.isFile()) {
+ // Try to open the file to ensure that this is possible: see bug 260217
+ // If access is denied, a FileNotFoundException with (access denied) message is
+ // thrown
+ // Here file.canRead() cannot be used, because on Windows it does not
+ // return correct values - bug 6203387 in Sun's bug database
+ InputStream is = new FileInputStream(file);
+ is.close();
+ } else if (file.isDirectory()) {
+ // There is no straightforward way to check if a directory
+ // has read permissions - same issues for File.canRead() as above;
+ // try to list the files in the directory
+ File[] files = file.listFiles();
+ // File.listFiles() returns null if the directory does not exist
+ // (which is not the current case, because we check that it exists and is
+ // directory),
+ // or if an IO error occurred during the listing of the files, including if the
+ // access is denied
+ if (files == null)
+ throw new FileNotFoundException(file.toString() + " (probably access denied)"); //$NON-NLS-1$
+ } else {
+ // TODO not sure if we can get here.
+ }
}
}

Back to the top