summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Fuller <nfuller@google.com>2014-09-17 13:25:37 +0100
committerNeil Fuller <nfuller@google.com>2014-09-17 13:25:37 +0100
commit95c68ff724f7cf1afc2970b0d25e108e580307ed (patch)
treed0d6f74d4c86a0784b183563175f97659392184d
parent64bbdb2e53712e7acc77fbb8b61a8888767610e0 (diff)
downloadlibcore-95c68ff724f7cf1afc2970b0d25e108e580307ed.zip
libcore-95c68ff724f7cf1afc2970b0d25e108e580307ed.tar.gz
libcore-95c68ff724f7cf1afc2970b0d25e108e580307ed.tar.bz2
Fix FilePreferencesImplTest test initialization errors.
Fix IllegalAccessException from Preferences when this test is run "stand alone". The java.util.prefs.Preferences class is normally already initialized by the time this test runs (and initialized when there is no system property). However, in standalone cases the system property is pointing to a class that cannot be instantiated by ServiceLoader. The normal fallback process when the system property is not set would lead to FilePreferencesFactoryImpl being instantiated directly by java.util.prefs.Preferences, which is legal. Removing the system property fixes the issue. The FilePreferencesFactoryImpl is not intended to be created by ServiceLoader and so it is reasonable that the class is declared as package-protected. This test is for the implementation so it's reasonable just to bypass Preferences entirely. Bug: 17515057 Change-Id: I02ea38b4a50fc3b7299a35d0a1050455cb9ca970
-rw-r--r--harmony-tests/src/test/java/org/apache/harmony/tests/java/util/prefs/FilePreferencesImplTest.java20
1 files changed, 5 insertions, 15 deletions
diff --git a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/prefs/FilePreferencesImplTest.java b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/prefs/FilePreferencesImplTest.java
index d2b344e..352603c 100644
--- a/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/prefs/FilePreferencesImplTest.java
+++ b/harmony-tests/src/test/java/org/apache/harmony/tests/java/util/prefs/FilePreferencesImplTest.java
@@ -26,31 +26,21 @@ import libcore.io.IoUtils;
public class FilePreferencesImplTest extends TestCase {
- private String prevFactory;
private Preferences uroot;
private Preferences sroot;
- private PreferencesFactory defaultFactory;
@Override
protected void setUp() throws Exception {
- prevFactory = System.getProperty("java.util.prefs.PreferencesFactory");
- System.setProperty("java.util.prefs.PreferencesFactory", "java.util.prefs.FilePreferencesFactoryImpl");
+ File tmpDir = IoUtils.createTemporaryDirectory("FilePreferencesImplTest");
+ AbstractPreferencesTest.TestPreferencesFactory factory
+ = new AbstractPreferencesTest.TestPreferencesFactory(tmpDir.getAbsolutePath());
- File tmpDir = IoUtils.createTemporaryDirectory("OldAbstractPreferencesTest");
- defaultFactory = Preferences.setPreferencesFactory(
- new AbstractPreferencesTest.TestPreferencesFactory(tmpDir.getAbsolutePath()));
-
- uroot = Preferences.userRoot().node("harmony_test");
- sroot = Preferences.systemRoot().node("harmony_test");
+ uroot = factory.userRoot().node("harmony_test");
+ sroot = factory.systemRoot().node("harmony_test");
}
@Override
protected void tearDown() throws Exception {
- Preferences.setPreferencesFactory(defaultFactory);
- if (prevFactory != null) {
- System.setProperty("java.util.prefs.PreferencesFactory", prevFactory);
- }
-
uroot.removeNode();
sroot.removeNode();
uroot = null;