You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2018/11/11 14:46:13 UTC
[incubator-netbeans] 01/03: [NETBEANS-1658] Revert "[NETBEANS-1197]
Avoid ClosedByInterruptException in NetBeans' classloader. Use NIO by
default,
but fall back to the old FileInputStream if ClosedByInterruptException is
detected."
This is an automated email from the ASF dual-hosted git repository.
matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-netbeans.git
commit 63eea8a40a9af4f981ca6361484b252faa6e1c3c
Author: Matthias Bläsing <mb...@doppel-helix.eu>
AuthorDate: Thu Nov 1 22:28:39 2018 +0100
[NETBEANS-1658] Revert "[NETBEANS-1197] Avoid ClosedByInterruptException in NetBeans' classloader. Use NIO by default, but fall back to the old FileInputStream if ClosedByInterruptException is detected."
This reverts commit f84b25e042e1a3eeb88afcc12805cd74bc5e4fd7.
---
.../src/org/netbeans/JarClassLoader.java | 74 ++++------------------
1 file changed, 12 insertions(+), 62 deletions(-)
diff --git a/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java b/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
index 77cc076..b1cdcc8 100644
--- a/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
+++ b/platform/o.n.bootstrap/src/org/netbeans/JarClassLoader.java
@@ -21,7 +21,6 @@ package org.netbeans;
import java.io.ByteArrayInputStream;
import java.io.File;
-import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
@@ -37,7 +36,6 @@ import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;
-import java.nio.channels.ClosedByInterruptException;
import java.nio.file.Files;
import java.nio.file.InvalidPathException;
import java.security.CodeSource;
@@ -852,41 +850,20 @@ public class JarClassLoader extends ProxyClassLoader {
super(BaseUtilities.toURI(file).toURL());
dir = file;
}
-
- private Manifest getManifestHelper(boolean useNIO) throws IOException {
- File maniF = new File(new File(dir, "META-INF"), "MANIFEST.MF");
- Manifest mf = new Manifest();
- if (maniF.canRead()) {
- try (InputStream istm = useNIO
- ? Files.newInputStream(maniF.toPath())
- : new FileInputStream(maniF))
- {
- mf.read(istm);
- }
- }
- return mf;
- }
-
+
public Manifest getManifest() {
Manifest mf = manifest;
if (mf != null) {
return mf;
}
- try {
- try {
- mf = getManifestHelper(true);
- } catch (ClosedByInterruptException ex) {
- // See comments in readClass().
- LOGGER.log(Level.INFO,
- "getManifest was interrupted; redoing operation with a regular FileInputStream");
- try {
- mf = getManifestHelper(false);
- } finally {
- Thread.currentThread().interrupt();
- }
+ File maniF = new File(new File(dir, "META-INF"), "MANIFEST.MF");
+ mf = new Manifest();
+ if (maniF.canRead()) {
+ try (InputStream istm = Files.newInputStream(maniF.toPath())) {
+ mf.read(istm);
+ } catch (IOException | InvalidPathException ex) {
+ Exceptions.printStackTrace(ex);
}
- } catch (IOException | InvalidPathException ex) {
- Exceptions.printStackTrace(ex);
}
return manifest = mf;
}
@@ -899,17 +876,14 @@ public class JarClassLoader extends ProxyClassLoader {
File resFile = new File(dir, name);
return resFile.exists() ? BaseUtilities.toURI(resFile).toURL() : null;
}
-
- private byte[] readClassHelper(String path, boolean usingNIO) throws IOException {
+
+ protected byte[] readClass(String path) throws IOException {
File clsFile = new File(dir, path.replace('/', File.separatorChar));
if (!clsFile.exists()) return null;
-
+
int len = (int)clsFile.length();
byte[] data = new byte[len];
- try (InputStream is = usingNIO
- ? Files.newInputStream(clsFile.toPath())
- : new FileInputStream(clsFile))
- {
+ try (InputStream is = Files.newInputStream(clsFile.toPath())) {
int count = 0;
while (count < len) {
count += is.read(data, count, len - count);
@@ -919,30 +893,6 @@ public class JarClassLoader extends ProxyClassLoader {
throw new IOException(ex);
}
}
-
- protected byte[] readClass(String path) throws IOException {
- /* "FileOutputStream and FileInputStream complicate GC because they both override
- 'finalize()'. Switching to NIO API creates Stream without finalizers and thus relieving
- GC." However, using NIO means IO operations can fail with a ClosedByInterruptException,
- for instance if client code starts a new thread which needs to load some new classes,
- and then interrupts the thread before class loading has finished. See NETBEANS-1197.
- Note that the old java.io.InterruptedIOException, which could in theory be called even
- from FileOutputStream/FileInputStream, was seldom seen in practice; see JDK-4385444. */
- try {
- return readClassHelper(path, true);
- } catch (ClosedByInterruptException ex) {
- LOGGER.log(Level.INFO,
- "readClass was interrupted; redoing operation with a regular FileInputStream");
- try {
- return readClassHelper(path, false);
- } finally {
- /* The wording in ClosedByInterruptException's Javadoc is a little ambiguous as to
- whether the thread's interrupt status will remain set _after_ the
- ClosedByInterruptException exception is thrown, so set it here just to be safe. */
- Thread.currentThread().interrupt();
- }
- }
- }
protected void listCoveredPackages(Set<String> known, StringBuffer save) {
appendAllChildren(known, save, dir, "");
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists