aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGlyn Normington2011-11-01 13:55:12 (EDT)
committerGlyn Normington2011-11-01 13:55:12 (EDT)
commit1bf3fd7ad6ce0c7b1a7c204eb2f326cf8b824163 (patch)
treed8e9f50c47cef06051c0726322468220a869da11
parent246444bd149b9b9affca47e1d5dedec970c98321 (diff)
downloadrt.equinox.bundles-1bf3fd7ad6ce0c7b1a7c204eb2f326cf8b824163.zip
rt.equinox.bundles-1bf3fd7ad6ce0c7b1a7c204eb2f326cf8b824163.tar.gz
rt.equinox.bundles-1bf3fd7ad6ce0c7b1a7c204eb2f326cf8b824163.tar.bz2
bug 361905: fail addition and removal of bundles from regions which are not part of a digraph
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMappingTests.java2
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java15
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdBasedRegion.java2
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdToRegionMapping.java15
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMapping.java2
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java12
6 files changed, 33 insertions, 15 deletions
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMappingTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMappingTests.java
index 04bdcc2..24178a8 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMappingTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMappingTests.java
@@ -60,7 +60,7 @@ public class StandardBundleIdToRegionMappingTests {
@Test
public void testDissociateBundle() throws BundleException {
this.bundleIdToRegionMapping.associateBundleWithRegion(TEST_BUNDLE_ID, mockRegion);
- this.bundleIdToRegionMapping.dissociateBundle(TEST_BUNDLE_ID);
+ this.bundleIdToRegionMapping.dissociateBundleFromRegion(TEST_BUNDLE_ID, mockRegion);
assertNull(this.bundleIdToRegionMapping.getRegion(TEST_BUNDLE_ID));
}
diff --git a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
index 05e2347..4443d19 100644
--- a/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
+++ b/bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java
@@ -599,17 +599,22 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
// Adding a bundle to a region should probably be an error
try {
pp1Region.addBundle(TEST_BUNDLE_ID);
- // TODO should fail if this succeeds?
- } catch (Exception e) {
- // TODO should be expected I think?
+ assertTrue("Added a bundle to a region which was not part of a digraph", true);
+ } catch (IllegalStateException e) {
+ // expected
}
assertNull("Region now associated with bundle id", digraph.getRegion(TEST_BUNDLE_ID));
Region pp2Region = digraph.createRegion(PP2);
pp2Region.addBundle(TEST_BUNDLE_ID);
+
// removing a bundle from a removed region should not change the digraph
- // TODO should be a no-op, or should some exception be thrown?
- pp1Region.removeBundle(TEST_BUNDLE_ID);
+ try {
+ pp1Region.removeBundle(TEST_BUNDLE_ID);
+ assertTrue("Removed a bundle via a region which was not part of a digraph", true);
+ } catch (IllegalStateException e) {
+ // Expected
+ }
assertEquals("Wrong region found for the bundle id", pp2Region, digraph.getRegion(TEST_BUNDLE_ID));
}
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdBasedRegion.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdBasedRegion.java
index d6a3670..478e9e8 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdBasedRegion.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdBasedRegion.java
@@ -207,7 +207,7 @@ final class BundleIdBasedRegion implements Region {
*/
@Override
public void removeBundle(long bundleId) {
- this.bundleIdToRegionMapping.dissociateBundle(bundleId);
+ this.bundleIdToRegionMapping.dissociateBundleFromRegion(bundleId, this);
}
/**
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdToRegionMapping.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdToRegionMapping.java
index a6a3802..896179a 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdToRegionMapping.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdToRegionMapping.java
@@ -13,6 +13,7 @@ package org.eclipse.equinox.internal.region;
import java.util.Set;
import org.eclipse.equinox.region.Region;
+import org.eclipse.equinox.region.RegionDigraph;
import org.osgi.framework.BundleException;
/**
@@ -28,20 +29,24 @@ public interface BundleIdToRegionMapping {
* id is already associated with a different region, throws {@link BundleException}.
* If the bundle id is already associated with the given region, there is no
* effect on the association and no exception is thrown.
+ * <p>
+ * If the given region does not belong to a {@link RegionDigraph} an
+ * {@link IllegalStateException} is thrown.
*
* @param bundleId the bundle id to be associated
* @param region the {@link Region} with which the bundle id is to be associated
- * @throws BundleException
+ * @throws BundleException if the bundle id is already associated with a different region
*/
void associateBundleWithRegion(long bundleId, Region region) throws BundleException;
/**
- * Dissociates the given bundle id with any region with which it may be
- * associated.
+ * Dissociates the given bundle id from the given region. If the given region
+ * does not belong to a {@link RegionDigraph} an {@link IllegalStateException} is thrown.
*
* @param bundleId the bundle id to be dissociated
+ * @param region the {@link Region} from which the bundle id is to be dissociated
*/
- void dissociateBundle(long bundleId);
+ void dissociateBundleFromRegion(long bundleId, Region region);
/**
* Dissociates any bundle ids which may be associated with the given region.
@@ -51,7 +56,7 @@ public interface BundleIdToRegionMapping {
/**
* Returns the {@link Region} associated with the given bundle id or <code>null</code>
- * if the given bundle id is not associated with a region.
+ * if the given bundle id is not associated with a region associated with a {@link RegionDigraph}.
*
* @param bundleId the bundle id whose region is required
* @return the {@link Region} associated with the given bundle id or or <code>null</code>
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMapping.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMapping.java
index 0a22b88..c3d6e60 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMapping.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardBundleIdToRegionMapping.java
@@ -44,7 +44,7 @@ final class StandardBundleIdToRegionMapping implements BundleIdToRegionMapping {
* {@inheritDoc}
*/
@Override
- public void dissociateBundle(long bundleId) {
+ public void dissociateBundleFromRegion(long bundleId, Region region) {
synchronized (this.monitor) {
this.bundleToRegion.remove(bundleId);
}
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
index d04c25a..80dabc3 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/StandardRegionDigraph.java
@@ -505,11 +505,18 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
@Override
public void associateBundleWithRegion(long bundleId, Region region) throws BundleException {
synchronized (this.monitor) {
+ checkRegionExists(region);
this.bundleIdToRegionMapping.associateBundleWithRegion(bundleId, region);
incrementUpdateCount();
}
}
+ private void checkRegionExists(Region region) {
+ if (!this.regions.contains(region)) {
+ throw new IllegalStateException("Operation not allowed on region " + region.getName() + " which is not part of a digraph"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+ }
+
private void incrementUpdateCount() {
synchronized (this.monitor) {
this.updateCount.incrementAndGet();
@@ -521,9 +528,10 @@ public final class StandardRegionDigraph implements BundleIdToRegionMapping, Reg
* {@inheritDoc}
*/
@Override
- public void dissociateBundle(long bundleId) {
+ public void dissociateBundleFromRegion(long bundleId, Region region) {
synchronized (this.monitor) {
- this.bundleIdToRegionMapping.dissociateBundle(bundleId);
+ checkRegionExists(region);
+ this.bundleIdToRegionMapping.dissociateBundleFromRegion(bundleId, region);
incrementUpdateCount();
}
}