diff options
author | Thomas Watson | 2014-09-30 19:09:30 +0000 |
---|---|---|
committer | Thomas Watson | 2014-09-30 19:09:30 +0000 |
commit | 341891705cb0f38ea99706755e998f27853f183e (patch) | |
tree | 030283cf9fee40bd2af44919b9d805295bc75cd5 /bundles | |
parent | 851e05741190a7ee914f2866fab48ff94faa60dd (diff) | |
download | rt.equinox.framework-341891705cb0f38ea99706755e998f27853f183e.tar.gz rt.equinox.framework-341891705cb0f38ea99706755e998f27853f183e.tar.xz rt.equinox.framework-341891705cb0f38ea99706755e998f27853f183e.zip |
Bug 445122 - ClassCastException received when System.getProperties().store() runs on 4.4.1
Diffstat (limited to 'bundles')
2 files changed, 36 insertions, 4 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java index dd1853ca0..393a5e156 100644 --- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java +++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/bundles/SystemBundleTests.java @@ -22,6 +22,7 @@ import junit.framework.TestSuite; import org.eclipse.osgi.internal.framework.EquinoxConfiguration; import org.eclipse.osgi.launch.Equinox; import org.eclipse.osgi.service.datalocation.Location; +import org.eclipse.osgi.service.environment.EnvironmentInfo; import org.eclipse.osgi.tests.OSGiTestsActivator; import org.junit.Assert; import org.osgi.framework.*; @@ -2207,6 +2208,30 @@ public class SystemBundleTests extends AbstractBundleTests { equinox.stop(); } + public void testNullConfigurationValueSystemProperties() throws BundleException { + System.setProperty(nullTest, "system"); + File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$ + Map<String, Object> configuration = new HashMap<String, Object>(); + configuration.put(Constants.FRAMEWORK_STORAGE, config.getAbsolutePath()); + configuration.put("osgi.framework.useSystemProperties", "true"); + configuration.put(nullTest, null); + Equinox equinox = new Equinox(configuration); + equinox.start(); + + String nullValue = equinox.getBundleContext().getProperty(nullTest); + assertNull(nullTest + " is not null: " + nullValue, nullValue); + assertNull("Did not get null system value.", System.getProperties().get(nullTest)); + + // also test EnvironmentInfo effects on system properties + ServiceReference<EnvironmentInfo> envRef = equinox.getBundleContext().getServiceReference(EnvironmentInfo.class); + EnvironmentInfo envInfo = equinox.getBundleContext().getService(envRef); + envInfo.setProperty(getName(), getName()); + assertEquals("Got wrong value from system properties.", System.getProperty(getName()), getName()); + envInfo.setProperty(getName(), null); + assertNull("Did not get null system value.", System.getProperties().get(getName())); + equinox.stop(); + } + public void testSystemNLFragment() throws BundleException { File config = OSGiTestsActivator.getContext().getDataFile(getName()); //$NON-NLS-1$ Map<String, Object> configuration = new HashMap<String, Object>(); diff --git a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java index f5642453d..7291438cf 100644 --- a/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java +++ b/bundles/org.eclipse.osgi/container/src/org/eclipse/osgi/internal/framework/EquinoxConfiguration.java @@ -67,6 +67,7 @@ public class EquinoxConfiguration implements EnvironmentInfo { private final Map<String, Object> initialConfig; private final Properties configuration; + private final boolean useSystemProperties; private final Debug debug; private final DebugOptions debugOptions; @@ -201,12 +202,16 @@ public class EquinoxConfiguration implements EnvironmentInfo { this.initialConfig = initialConfiguration == null ? new HashMap<String, Object>(0) : new HashMap<String, Object>(initialConfiguration); this.hookRegistry = hookRegistry; Object useSystemPropsValue = initialConfig.get(PROP_USE_SYSTEM_PROPERTIES); - boolean useSystemProps = useSystemPropsValue == null ? false : Boolean.parseBoolean(useSystemPropsValue.toString()); - this.configuration = useSystemProps ? System.getProperties() : new Properties(); + this.useSystemProperties = useSystemPropsValue == null ? false : Boolean.parseBoolean(useSystemPropsValue.toString()); + this.configuration = useSystemProperties ? System.getProperties() : new Properties(); // do this the hard way to handle null values for (Map.Entry<String, ?> initialEntry : this.initialConfig.entrySet()) { if (initialEntry.getValue() == null) { - this.configuration.put(initialEntry.getKey(), NULL_CONFIG); + if (useSystemProperties) { + this.configuration.remove(initialEntry.getKey()); + } else { + this.configuration.put(initialEntry.getKey(), NULL_CONFIG); + } } else { this.configuration.put(initialEntry.getKey(), initialEntry.getValue()); } @@ -446,7 +451,9 @@ public class EquinoxConfiguration implements EnvironmentInfo { public String clearConfiguration(String key) { Object result = configuration.remove(key); - configuration.put(key, NULL_CONFIG); + if (!useSystemProperties) { + configuration.put(key, NULL_CONFIG); + } return result instanceof String ? (String) result : null; } |