<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<div>For store method, I wish it was:
<div>1. Null comment, meant no comment and no date.</div>
<div>2. Empty comment, meant date only.</div>
<div>3. Not blank comment, meant comment line and date.</div>
<div><br>
</div>
<div>However, too late to change that behavior.</div>
<div><br>
</div>
<div>It would be nice if the JDK had a FilterWriter implementation that decorated a Writer to ignore all comments lines. Properties itself could provide a factory method since it already knows about Writer.</div>
<div><br>
</div>
Jason<br>
</div>
<br>
<div></div>
<br>
<hr style="display:inline-block;width:98%" tabindex="-1">
<div id="divRplyFwdMsg" dir="ltr"><font face="Calibri, sans-serif" style="font-size:11pt" color="#000000"><b>From:</b> core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Jaikiran Pai <jai.forums2013@gmail.com><br>
<b>Sent:</b> Wednesday, November 27, 2024 1:34 AM<br>
<b>To:</b> core-libs-dev@openjdk.org <core-libs-dev@openjdk.org><br>
<b>Subject:</b> Re: java.util.Properties: reproducible write</font>
<div> </div>
</div>
<div class="BodyFragment"><font size="2"><span style="font-size:11pt;">
<div class="PlainText">Hello Rob,<br>
<br>
On 27/11/24 12:52 am, Rob Spoor wrote:<br>
> The comment provided in `store(Writer, String)` is added in addition <br>
> to the date comment:<br>
><br>
> if (comments != null) {<br>
> writeComments(bw, comments);<br>
> }<br>
> writeDateComment(bw);<br>
><br>
> The system property can be used to replace the date with a constant, <br>
> but a) it's not possible to omit it because an empty property value <br>
> still leads to the date being written,<br>
<br>
The caller of Properties.store(Writer, String), if they pass null to the <br>
comments parameter, then an attempt will be made to write out a comment. <br>
The value for that comment will come from a system property named <br>
java.properties.date. The value can be any free form text <br>
<a href="https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/Properties.html#java.properties.date" data-auth="NotApplicable">https://docs.oracle.com/en/java/javase/23/docs/api/java.base/java/util/Properties.html#java.properties.date</a>.
<br>
A blank (not empty) value can be set for that system property and that <br>
will write out just whitespace as the comment line. Here's a test which <br>
shows that usage <br>
<a href="https://github.com/openjdk/jdk/blob/master/test/jdk/java/util/Properties/StoreReproducibilityTest.java#L106" data-auth="NotApplicable">https://github.com/openjdk/jdk/blob/master/test/jdk/java/util/Properties/StoreReproducibilityTest.java#L106</a>.<br>
<br>
> b) it's a global setting, not something to apply to a single <br>
> Properties instance, and c) you need to set it when starting the JVM <br>
> because its value is cached (tested in jshell).<br>
><br>
> Perhaps adding an enum Properties.StoreProperties with single constant <br>
> OMIT_DATE can be used:<br>
<br>
The change to support reproducibility for Properties.store() went <br>
through several rounds of discussions, including proposed overloads to <br>
methods, before we settled on the current implementation. Some of those <br>
discussions are here:<br>
<br>
<a href="https://mail.openjdk.org/pipermail/core-libs-dev/2021-August/080758.html" data-auth="NotApplicable">https://mail.openjdk.org/pipermail/core-libs-dev/2021-August/080758.html</a><br>
<br>
<a href="https://mail.openjdk.org/pipermail/core-libs-dev/2021-September/081113.html" data-auth="NotApplicable">https://mail.openjdk.org/pipermail/core-libs-dev/2021-September/081113.html</a><br>
<br>
<a href="https://github.com/openjdk/jdk/pull/5372" data-auth="NotApplicable">https://github.com/openjdk/jdk/pull/5372</a><br>
<br>
-Jaikiran<br>
<br>
><br>
> // overload, not replacement; similar for OutputStream<br>
> public void store(Writer writer, String comments, <br>
> StoreProperties... properties)<br>
><br>
> This can then be called as props.store(writer, null, <br>
> Properties.StoreProperties.OMIT_DATE).<br>
><br>
><br>
> Rob<br>
><br>
> On 26/11/2024 00:23, Roger Riggs wrote:<br>
>> Hi Rafael,<br>
>><br>
>> You might have missed the update added by JDK-8231640 <https:// <br>
>> bugs.openjdk.org/browse/JDK-8231640> Canonical property storage<br>
>> The comment string can be provided either by a separate method <br>
>> `store(Writer, String)` or by a system property.<br>
>><br>
>> Regards, Roger<br>
>><br>
>> On 11/25/24 4:53 PM, Rafael Winterhalter wrote:<br>
>>> Hello,<br>
>>><br>
>>> I find the java.util.Properties class to be quite convenient when <br>
>>> writing minor collections of key-values. One unfortunate implication <br>
>>> of the store method is that it always contains a comment line with <br>
>>> the current date. The comment is never deserialized when loading the <br>
>>> file, but the file hash is of course always changed, even if the <br>
>>> content is identical at a later time. This can have unfortunate <br>
>>> implications when the file hash is relevant to some form of cashing <br>
>>> or validation mechanism.<br>
>>><br>
>>> Would it be a good idea to add an overload that allows disabling the <br>
>>> date comment? This would only require minimal code changes and the <br>
>>> storage format would become reproducible. The key-values are already <br>
>>> sorted by their key. The date can be fixed by a system property, but <br>
>>> this is not always possible to define if the writer is not in <br>
>>> control of the command line. Right now I have to reimplement the <br>
>>> Properties::store method only to exclude this line.<br>
>>><br>
>>> Thanks for your consideration and opinion,<br>
>>> Rafael<br>
>><br>
><br>
</div>
</span></font></div>
</body>
</html>