diff options
author | Neil Fuller <nfuller@google.com> | 2014-09-17 13:25:37 +0100 |
---|---|---|
committer | Neil Fuller <nfuller@google.com> | 2014-09-22 15:04:11 +0100 |
commit | 9252ce2bef667745ad23601d5ac25b435e6e77f5 (patch) | |
tree | 00ed09d4c4c4576f649bcc784001f4a232ce8ecf /harmony-tests | |
parent | 65cbc395d35f892f02c4868486b699a7d962ee47 (diff) | |
download | libcore-9252ce2bef667745ad23601d5ac25b435e6e77f5.zip libcore-9252ce2bef667745ad23601d5ac25b435e6e77f5.tar.gz libcore-9252ce2bef667745ad23601d5ac25b435e6e77f5.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
(cherry picked from commit 95c68ff724f7cf1afc2970b0d25e108e580307ed)
Change-Id: Ia860e299983b7b87753fe1dc0259b0d4ea2477f3
Diffstat (limited to 'harmony-tests')
-rw-r--r-- | harmony-tests/src/test/java/org/apache/harmony/tests/java/util/prefs/FilePreferencesImplTest.java | 20 |
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; |