commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 35804] - [configuration] Make Configuration Serializable
Date Thu, 21 Jul 2005 18:17:49 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG·
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://issues.apache.org/bugzilla/show_bug.cgi?id=35804>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND·
INSERTED IN THE BUG DATABASE.

http://issues.apache.org/bugzilla/show_bug.cgi?id=35804





------- Additional Comments From ebourg@apache.org  2005-07-21 20:17 -------
This is not as trivial as I thought initially... I made FileConfiguration
extends Serializable and wrote a test case serializing a PropertiesConfiguration
to a file. This led me to the following changes:

- make ReloadingStrategy extend Serializable as well
- change the type of the reloadLock in AbtractFileConfiguration to something
else than Object that is serializable. I picked String. I tried to make it
transient, but it resulted in a NullPointerException when accessing the
deserialized configuration because it was not initialized. I tried to move the
initialization in the no arg constructor but it didn't work, I'm not sure to
understand why this constructor isn't called when the deserialized instance is
build.

It still failed after these changes, because the deserialized configuration was
actually empty. It appears that the Map in BaseConfiguration is not serialized.
I put a similar Map in AbstractFileConfiguration and it got serialized property,
but by simply moving this Map to BaseConfiguration it disappeared from the
serialized file, I have no idea why.

I tested with the JDK 1.4.2_08.

Here is the test added to TestPropertiesConfiguration:

    public void testSerialization() throws Exception {
        // remove the previous serialization file
        File file = new File("target/configuration.ser");
        if (file.exists()) {
            file.delete();
        }

        // write the configuration to the configuration.ser file
        ObjectOutputStream out = new ObjectOutputStream(new FileOutputStream(file));
        out.writeObject(conf);
        out.close();

        // load the configuration from the file
        ObjectInputStream in = new ObjectInputStream(new FileInputStream(file));
        PropertiesConfiguration conf2 = (PropertiesConfiguration) in.readObject();
        in.close();

        // check the deserialized configuration
        assertNotNull("deserialized configuration null", conf2);
        assertEquals("filename", conf.getFileName(), conf2.getFileName());
        assertEquals("basepath", conf.getBasePath(), conf2.getBasePath());
        assertEquals("header", conf.getHeader(), conf2.getHeader());

        assertFalse("deserialized configuration empty", conf2.isEmpty());
        Iterator keys = conf.getKeys();
        while (keys.hasNext())
        {
            String key = (String) keys.next();
            assertTrue("missing key from the deserialized configuration : " +
key, conf2.containsKey(key));
            assertEquals("wrong value in the deserialized configuration for the
key " + key, conf.getProperty(key), conf2.getProperty(key));
        }
    }


-- 
Configure bugmail: http://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug, or are watching the assignee.

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message