diff options
2 files changed, 35 insertions, 10 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java index 4d603a0f9..92048c5b4 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/BundleInstallUpdateTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 IBM Corporation and others. + * Copyright (c) 2009, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -272,4 +272,22 @@ public class BundleInstallUpdateTests extends AbstractBundleTests { reg.unregister(); } } + + public void testInstallWithInterruption() { + Bundle test = null; + Thread.currentThread().interrupt(); + try { + test = installer.installBundle("test"); //$NON-NLS-1$ + } catch (BundleException e) { + fail("Unexpected failure", e); //$NON-NLS-1$ + } finally { + Thread.interrupted(); + try { + if (test != null) + test.uninstall(); + } catch (BundleException e) { + // nothing + } + } + } } diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/LockSet.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/LockSet.java index 2db897851..360fa1306 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/LockSet.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/container/LockSet.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2012, 2014 IBM Corporation and others. + * Copyright (c) 2012, 2015 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -40,17 +40,24 @@ public class LockSet<T> { locks.put(t, lock); } } - boolean obtained = !lock.isHeldByCurrentThread() && lock.tryLock(time, unit); - if (obtained) { - synchronized (monitor) { - // must check that another thread did not remove the lock - // when unlocking while we were waiting to obtain the lock - if (!locks.containsKey(t)) { - locks.put(t, lock); + boolean previousInterruption = Thread.interrupted(); + try { + boolean obtained = !lock.isHeldByCurrentThread() && lock.tryLock(time, unit); + if (obtained) { + synchronized (monitor) { + // must check that another thread did not remove the lock + // when unlocking while we were waiting to obtain the lock + if (!locks.containsKey(t)) { + locks.put(t, lock); + } } } + return obtained; + } finally { + if (previousInterruption) { + Thread.currentThread().interrupt(); + } } - return obtained; } public void unlock(T t) { |