FULL PRODUCT VERSION :
1.7.0_17
ADDITIONAL OS VERSION INFORMATION :
Version 6.0.6000
EXTRA RELEVANT SYSTEM CONFIGURATION :
Not system related
A DESCRIPTION OF THE PROBLEM :
If you construct a Properties object with a default Properties object in the constructor, add some more properties, and then dump the results with storeToXML you get different results when running Java 6 and Java 7.
Java 6 only exports the new properties and not the defaults.
Java 7 (1.7.0_17) includes the defaults.
The Store method does not export the defaults.
REGRESSION. Last worked in version 6u45
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
Create a Properties object A.
Add properties.
Construct a new Properties object B using A as the default.
Add more properties.
Export using storeToXML.
Compare J7 output with J6.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
Result from Java6
<?xml version= " 1.0 " encoding= " UTF-8 " standalone= " no " ?>
<!DOCTYPE properties SYSTEM " http://java.sun.com/dtd/properties.dtd " >
<properties>
<comment>Try export with 1.6.0_35</comment>
<entry key= " common " >This property is from B</entry>
<entry key= " name_propB " >This property is from B</entry>
</properties>
ACTUAL -
Result from Java 7
<?xml version= " 1.0 " encoding= " UTF-8 " standalone= " no " ?>
<!DOCTYPE properties SYSTEM " http://java.sun.com/dtd/properties.dtd " >
<properties>
<comment>Try export with 1.7.0_17</comment>
<entry key= " common " >This property is from B</entry>
<entry key= " name_propB " >This property is from B</entry>
<entry key= " name_propA " >This property is from A</entry>
</properties>
REPRODUCIBILITY :
This bug can be reproduced always.
---------- BEGIN SOURCE ----------
import java.util.Properties;
import java.io.FileOutputStream;
import java.io.File;
class TestProperties {
public static void main(String[] args) {
String outputName = args.length > 0 ? args[0] : " dump.txt " ;
System.out.println( " Java version " + System.getProperty( " java.version " ));
Properties propsA = new Properties();
propsA.setProperty( " name_propA " , " This property is from A " );
propsA.setProperty( " common " , " This property is from A " );
Properties propsB = new Properties(propsA);
propsB.setProperty( " name_propB " , " This property is from B " );
propsB.setProperty( " common " , " This property is from B " );
try {
FileOutputStream fo = new FileOutputStream(new File(outputName));
propsB.storeToXML(fo, " Try export with " + System.getProperty( " java.version " ));
} catch (Exception ex) {
System.out.println( " Exception " + ex);
}
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
This can be worked around if the difference in behavour is known. However, there is nothing I can see in the Javadocs that would have made the behaviour change apparent. The documentation for 6 and 7 appears ambiguous as to which behaviour is correct.
Difficult to see how the behaviour can be 'corrected' now as any change will have a impact on already distributed code. However, the Javadocs could flag the difference.