Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2012-03-19 16:02:13 +0000
committerThomas Watson2012-03-19 16:02:13 +0000
commit96b97263b06ccef1ee05dd2957592f640bacb94b (patch)
tree4053b8bb8a144d6ea175c341cc2962c743ac299b
parent34170596b63a67e8aa4227470b241d381564ff3d (diff)
downloadrt.equinox.bundles-96b97263b06ccef1ee05dd2957592f640bacb94b.tar.gz
rt.equinox.bundles-96b97263b06ccef1ee05dd2957592f640bacb94b.tar.xz
rt.equinox.bundles-96b97263b06ccef1ee05dd2957592f640bacb94b.zip
Bug 374493 - [region] invalid region name causes failure to registerv20120319-1602
MBean
-rw-r--r--bundles/org.eclipse.equinox.region.tests/src/org/eclipse/equinox/region/tests/system/RegionSystemTests.java31
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/BundleIdBasedRegion.java13
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/RegionObjectNameCreator.java10
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/StandardManageableRegionDigraph.java10
-rw-r--r--bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java17
5 files changed, 58 insertions, 23 deletions
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 fe401aa1..c8bd9b36 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
@@ -655,12 +655,27 @@ public class RegionSystemTests extends AbstractRegionSystemTest {
assertEquals("Wrong location found.", location + ".2", l2);
}
- // public void testInvalidRegionName() {
- // String invalidName = "name:withColon";
- // try {
- // digraph.createRegion(invalidName);
- // } catch (Exception e) {
- // fail("failed to create region: " + invalidName);
- // }
- // }
+ public void testInvalidRegionName() {
+ Collection<String> invalidNames = new ArrayList<String>();
+ invalidNames.addAll(Arrays.asList(":", "bad:Name", ":bad::name:", ":badname", "badname:"));
+ invalidNames.addAll(Arrays.asList("=", "bad=Name", "=bad==name=", "=badname", "badname="));
+ invalidNames.addAll(Arrays.asList("\n", "bad\nName", "\nbad\n\nname\n", "\nbadname", "badname\n"));
+ invalidNames.addAll(Arrays.asList("*", "bad*Name", "*bad**name*", "*badname", "badname*"));
+ invalidNames.addAll(Arrays.asList("?", "bad?Name", "?bad??name?", "?badname", "badname?"));
+ invalidNames.addAll(Arrays.asList(",", "bad,Name", ",bad,,name,", ",badname", "badname,"));
+ invalidNames.addAll(Arrays.asList("\"", "bad\"Name", "\"bad\"\"name\"", "\"badname", "badname\""));
+ invalidNames.addAll(Arrays.asList("\\", "bad\\Name", "\\bad\\\\name\\", "\\badname", "badname\\"));
+
+ for (String invalidName : invalidNames) {
+ try {
+ digraph.createRegion(invalidName);
+ fail("Expected failure to create region.");
+ } catch (IllegalArgumentException e) {
+ // expected
+ } catch (BundleException e) {
+ fail("Unexpected bundle exception: " + e.getMessage());
+ }
+ }
+
+ }
}
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 7a5c2d9d..22247dcf 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
@@ -16,6 +16,7 @@ import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Set;
+import java.util.regex.Pattern;
import org.eclipse.equinox.region.*;
import org.eclipse.equinox.region.RegionDigraph.FilteredRegion;
import org.osgi.framework.*;
@@ -29,7 +30,7 @@ import org.osgi.framework.*;
* Thread safe.
*/
final class BundleIdBasedRegion implements Region {
-
+ private static final Pattern invalidName = Pattern.compile("[:=\\n*?,\"\\\\]"); //$NON-NLS-1$
private static final String REGION_LOCATION_DELIMITER = "#"; //$NON-NLS-1$
private static final String FILE_SCHEME = "file:"; //$NON-NLS-1$
@@ -45,8 +46,7 @@ final class BundleIdBasedRegion implements Region {
private final ThreadLocal<Region> threadLocal;
BundleIdBasedRegion(String regionName, RegionDigraph regionDigraph, BundleIdToRegionMapping bundleIdToRegionMapping, BundleContext bundleContext, ThreadLocal<Region> threadLocal) {
- if (regionName == null)
- throw new IllegalArgumentException("The region name must not be null"); //$NON-NLS-1$
+ BundleIdBasedRegion.validateName(regionName);
if (regionDigraph == null)
throw new IllegalArgumentException("The region digraph must not be null"); //$NON-NLS-1$
if (bundleIdToRegionMapping == null)
@@ -58,6 +58,13 @@ final class BundleIdBasedRegion implements Region {
this.threadLocal = threadLocal;
}
+ private static void validateName(String name) {
+ if (name == null)
+ throw new IllegalArgumentException("The region name must not be null"); //$NON-NLS-1$
+ if (invalidName.matcher(name).find())
+ throw new IllegalArgumentException("The region name has invalid characters: " + name); //$NON-NLS-1$
+ }
+
/**
* {@inheritDoc}
*/
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/RegionObjectNameCreator.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/RegionObjectNameCreator.java
index 09fb6af7..93fe027d 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/RegionObjectNameCreator.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/RegionObjectNameCreator.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
+ * Copyright (c) 2011, 2012 VMware Inc.
* 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
@@ -33,14 +33,14 @@ final class RegionObjectNameCreator {
}
ObjectName getRegionObjectName(String regionName) {
+ String name = this.domain + ":type=Region,name=" + regionName; //$NON-NLS-1$
+ if (frameworkUUID != null)
+ name += ",frameworkUUID=" + frameworkUUID; //$NON-NLS-1$
try {
- String name = this.domain + ":type=Region,name=" + regionName; //$NON-NLS-1$
- if (frameworkUUID != null)
- name += ",frameworkUUID=" + frameworkUUID; //$NON-NLS-1$
return new ObjectName(name);
} catch (MalformedObjectNameException e) {
e.printStackTrace();
- return null;
+ throw new IllegalArgumentException("Invalid region name '" + regionName + "' resulting in an invalid object name '" + name + "'", e); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
}
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/StandardManageableRegionDigraph.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/StandardManageableRegionDigraph.java
index f3999528..a1112423 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/StandardManageableRegionDigraph.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/internal/region/management/StandardManageableRegionDigraph.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
+ * Copyright (c) 2011, 2012 VMware Inc.
* 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
@@ -71,14 +71,14 @@ public final class StandardManageableRegionDigraph implements ManageableRegionDi
this.mbeanServer = ManagementFactory.getPlatformMBeanServer();
this.frameworkUUID = bundleContext.getProperty(Constants.FRAMEWORK_UUID);
this.regionObjectNameCreator = new RegionObjectNameCreator(domain, this.frameworkUUID);
+ String name = this.domain + ":type=RegionDigraph"; //$NON-NLS-1$
+ if (frameworkUUID != null)
+ name += ",frameworkUUID=" + frameworkUUID; //$NON-NLS-1$
try {
- String name = this.domain + ":type=RegionDigraph"; //$NON-NLS-1$
- if (frameworkUUID != null)
- name += ",frameworkUUID=" + frameworkUUID; //$NON-NLS-1$
mbeanName = new ObjectName(name);
} catch (MalformedObjectNameException e) {
e.printStackTrace();
- throw new RuntimeException("Invalid domain name '" + this.domain + "'", e); //$NON-NLS-1$//$NON-NLS-2$
+ throw new IllegalArgumentException("Invalid domain name '" + domain + "' resulting in an invalid object name '" + name + "'", e); //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
}
}
diff --git a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java
index 9d30db95..aca70f1e 100644
--- a/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java
+++ b/bundles/org.eclipse.equinox.region/src/org/eclipse/equinox/region/RegionDigraph.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2011 VMware Inc.
+ * Copyright (c) 2011, 2012 VMware Inc.
* 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
@@ -65,11 +65,24 @@ public interface RegionDigraph extends Iterable<Region> {
/**
* Create a {@link Region} with the given name. If a region with the given name already exists, then BundleException
- * with exception type UNSUPPORTED_OPERATION is thrown.
+ * with exception type UNSUPPORTED_OPERATION is thrown. If the region name is not valid then an
+ * IllegalArgumentException is thrown. A valid region name contains none of the following
+ * characters:
+ * <ul>
+ * <li> : (colon)</li>
+ * <li> = (equals)</li>
+ * <li> \n (newline)</li>
+ * <li> * (asterisk)</li>
+ * <li> ? (question mark)</li>
+ * <li> , (comma)</li>
+ * <li> &quot; (double quotes)</li>
+ * <li> \ (backslash)</li>
+ * </ul>
*
* @param regionName the name of the region
* @return the {@link Region} created
* @throws BundleException if the region was not created
+ * @throws IllegalArgumentException if the region name is not valid
*/
Region createRegion(String regionName) throws BundleException;

Back to the top