diff options
| author | Thomas Watson | 2014-09-30 19:09:30 +0000 |
|---|---|---|
| committer | Thomas Watson | 2014-10-15 12:44:50 +0000 |
| commit | 5e48a84c3ab338b20065173e4a572e34a427642b (patch) | |
| tree | b46ebca40a26041adf55c364632cad16c12abb88 | |
| parent | ec8d374e48d723d61ff297fd61a1c19304b8815a (diff) | |
| download | rt.equinox.framework-5e48a84c3ab338b20065173e4a572e34a427642b.tar.gz rt.equinox.framework-5e48a84c3ab338b20065173e4a572e34a427642b.tar.xz rt.equinox.framework-5e48a84c3ab338b20065173e4a572e34a427642b.zip | |
Bug 445122 - ClassCastException received when System.getProperties().store() runs on 4.4.1
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 52a4d4a7c..af0a1514d 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; } |
