Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2008-11-06 20:29:43 +0000
committerThomas Watson2008-11-06 20:29:43 +0000
commitd6fe8d84a67d4c54538e924ce18d8e88a90b1eb6 (patch)
treef9f0e12c1b531cc35a2938854b048a92f141c571 /bundles/org.eclipse.osgi/defaultAdaptor
parent9596af330014315ac06196169f8d303cbfcf1056 (diff)
downloadrt.equinox.framework-d6fe8d84a67d4c54538e924ce18d8e88a90b1eb6.tar.gz
rt.equinox.framework-d6fe8d84a67d4c54538e924ce18d8e88a90b1eb6.tar.xz
rt.equinox.framework-d6fe8d84a67d4c54538e924ce18d8e88a90b1eb6.zip
Bug 253942 MRUBundleFileList causes IllegalStateException when restarting Equinox instance
Diffstat (limited to 'bundles/org.eclipse.osgi/defaultAdaptor')
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry.java17
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile.java56
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorage.java7
-rw-r--r--bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorageHook.java5
4 files changed, 58 insertions, 27 deletions
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry.java
index da101d0e9..52f465d2a 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleEntry.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Rob Harrop - SpringSource Inc. (bug 253942)
*******************************************************************************/
package org.eclipse.osgi.baseadaptor.bundlefile;
@@ -24,19 +25,19 @@ public class ZipBundleEntry extends BundleEntry {
/**
* ZipEntry for this entry.
*/
- protected ZipEntry zipEntry;
+ protected final ZipEntry zipEntry;
/**
* The BundleFile for this entry.
*/
- protected BundleFile bundleFile;
+ protected final ZipBundleFile bundleFile;
/**
* Constructs the BundleEntry using a ZipEntry.
* @param bundleFile BundleFile object this entry is a member of
* @param zipEntry ZipEntry object of this entry
*/
- ZipBundleEntry(ZipEntry zipEntry, BundleFile bundleFile) {
+ ZipBundleEntry(ZipEntry zipEntry, ZipBundleFile bundleFile) {
this.zipEntry = zipEntry;
this.bundleFile = bundleFile;
}
@@ -48,9 +49,11 @@ public class ZipBundleEntry extends BundleEntry {
* @exception java.io.IOException
*/
public InputStream getInputStream() throws IOException {
- if (!ZipBundleFile.mruList.isEnabled())
- return ((ZipBundleFile) bundleFile).getZipFile().getInputStream(zipEntry);
- ZipBundleFile zipBundleFile = (ZipBundleFile) bundleFile;
+ ZipBundleFile zipBundleFile = bundleFile;
+
+ if (!zipBundleFile.isMruEnabled())
+ return bundleFile.getZipFile().getInputStream(zipEntry);
+
zipBundleFile.incrementReference();
InputStream result = null;
try {
@@ -132,7 +135,7 @@ public class ZipBundleEntry extends BundleEntry {
return;
closed = true;
}
- ((ZipBundleFile) bundleFile).decrementReference();
+ bundleFile.decrementReference();
}
}
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile.java
index 7bd9f4f2b..ac9f32c22 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/baseadaptor/bundlefile/ZipBundleFile.java
@@ -7,12 +7,14 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Rob Harrop - SpringSource Inc. (bug 253942)
*******************************************************************************/
package org.eclipse.osgi.baseadaptor.bundlefile;
import java.io.*;
-import java.util.*;
+import java.util.Enumeration;
+import java.util.Vector;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.eclipse.osgi.baseadaptor.BaseData;
@@ -27,8 +29,8 @@ import org.osgi.framework.FrameworkEvent;
* @since 3.2
*/
public class ZipBundleFile extends BundleFile {
- protected static MRUBundleFileList mruList = new MRUBundleFileList();
+ private final MRUBundleFileList mruList;
/**
* The bundle data
*/
@@ -36,11 +38,11 @@ public class ZipBundleFile extends BundleFile {
/**
* The zip file
*/
- protected ZipFile zipFile;
+ protected volatile ZipFile zipFile;
/**
* The closed flag
*/
- protected boolean closed = true;
+ protected volatile boolean closed = true;
private int referenceCount = 0;
@@ -51,11 +53,16 @@ public class ZipBundleFile extends BundleFile {
* @throws IOException
*/
public ZipBundleFile(File basefile, BaseData bundledata) throws IOException {
+ this(basefile, bundledata, null);
+ }
+
+ public ZipBundleFile(File basefile, BaseData bundledata, MRUBundleFileList mruList) throws IOException {
super(basefile);
if (!BundleFile.secureAction.exists(basefile))
throw new IOException(NLS.bind(AdaptorMsg.ADAPTER_FILEEXIST_EXCEPTION, basefile));
this.bundledata = bundledata;
this.closed = true;
+ this.mruList = mruList;
}
/**
@@ -90,11 +97,11 @@ public class ZipBundleFile extends BundleFile {
*/
protected synchronized ZipFile getZipFile() throws IOException {
if (closed) {
- mruList.add(this);
+ mruListAdd();
zipFile = basicOpen();
closed = false;
} else
- mruList.use(this);
+ mruListUse();
return zipFile;
}
@@ -287,7 +294,7 @@ public class ZipBundleFile extends BundleFile {
public synchronized void close() throws IOException {
if (!closed) {
- if (referenceCount > 0 && mruList.isClosing(this)) {
+ if (referenceCount > 0 && isMruListClosing()) {
// there are some opened streams to this BundleFile still;
// wait for them all to close because this is being closed by the MRUBundleFileList
try {
@@ -304,19 +311,38 @@ public class ZipBundleFile extends BundleFile {
}
closed = true;
zipFile.close();
- mruList.remove(this);
+ mruListRemove();
}
}
- public void open() throws IOException {
- //do nothing
+ private boolean isMruListClosing() {
+ return this.mruList != null && this.mruList.isClosing(this);
}
- /**
- * Shutsdown the bundle file closer thread for zip bundle files
- */
- public static void shutdown() {
- mruList.shutdown();
+ boolean isMruEnabled() {
+ return this.mruList != null && this.mruList.isEnabled();
+ }
+
+ private void mruListRemove() {
+ if (this.mruList != null) {
+ this.mruList.remove(this);
+ }
+ }
+
+ private void mruListUse() {
+ if (this.mruList != null) {
+ mruList.use(this);
+ }
+ }
+
+ private void mruListAdd() {
+ if (this.mruList != null) {
+ mruList.add(this);
+ }
+ }
+
+ public void open() {
+ //do nothing
}
synchronized void incrementReference() {
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorage.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorage.java
index 19a570343..231e10554 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorage.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorage.java
@@ -7,7 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
- * Rob Harrop - SpringSource Inc. (bug 247520)
+ * Rob Harrop - SpringSource Inc. (bug 247520 and 253942)
*******************************************************************************/
package org.eclipse.osgi.internal.baseadaptor;
@@ -84,6 +84,8 @@ public class BaseStorage implements SynchronousBundleListener {
private static final String PERM_DATA_FILE = ".permdata"; //$NON-NLS-1$
private static final byte PERMDATA_VERSION = 1;
+ private final MRUBundleFileList mruList = new MRUBundleFileList();
+
private BaseAdaptor adaptor;
// assume a file: installURL
private String installPath;
@@ -674,7 +676,7 @@ public class BaseStorage implements SynchronousBundleListener {
if (file.isDirectory())
result = new DirBundleFile(file);
else
- result = new ZipBundleFile(file, data);
+ result = new ZipBundleFile(file, data, this.mruList);
}
if (result == null && content instanceof String) {
@@ -834,6 +836,7 @@ public class BaseStorage implements SynchronousBundleListener {
storageManagerClosed = true;
if (extensionListener != null)
context.removeBundleListener(extensionListener);
+ mruList.shutdown();
}
public void frameworkStopping(BundleContext fwContext) {
diff --git a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorageHook.java b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorageHook.java
index 9a1ccb025..bf3e4d9c1 100644
--- a/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorageHook.java
+++ b/bundles/org.eclipse.osgi/defaultAdaptor/src/org/eclipse/osgi/internal/baseadaptor/BaseStorageHook.java
@@ -7,6 +7,7 @@
*
* Contributors:
* IBM Corporation - initial API and implementation
+ * Rob Harrop - SpringSource Inc. (bug 253942)
*******************************************************************************/
package org.eclipse.osgi.internal.baseadaptor;
@@ -20,7 +21,6 @@ import org.eclipse.core.runtime.adaptor.LocationManager;
import org.eclipse.osgi.baseadaptor.BaseAdaptor;
import org.eclipse.osgi.baseadaptor.BaseData;
import org.eclipse.osgi.baseadaptor.bundlefile.BundleEntry;
-import org.eclipse.osgi.baseadaptor.bundlefile.ZipBundleFile;
import org.eclipse.osgi.baseadaptor.hooks.AdaptorHook;
import org.eclipse.osgi.baseadaptor.hooks.StorageHook;
import org.eclipse.osgi.framework.adaptor.*;
@@ -345,8 +345,7 @@ public class BaseStorageHook implements StorageHook, AdaptorHook {
}
public void frameworkStop(BundleContext context) throws BundleException {
- // shutdown the bundle file closer thread if it exists
- ZipBundleFile.shutdown();
+ // do nothing
}
public void frameworkStopping(BundleContext context) {

Back to the top