What happens to lines of Java .properties file which don't match the key value pattern

I have a java library which I need to treat as a black box and which requires a properties file to exist on the class path. However, I have a system in place which only allows the serving of configuration files which contain valid xml.

Due to the black box nature of the jar I am unable to recompile using the loadFromXml() method, or ask the owner so to do.

To solve this apparent mismatch I have been able to provide a config file which look like this:

<dummy>
key1=value1
key2=value2
</dummy>

This works fine and provides the values that I want access to.

I can not find a reference to what happens to the first and last line of this malformed properties file.

Does anybody know what happens? Do they have a better solution?

Jon Skeet
people
quotationmark

You end up with an empty string value for the keys "<dummy>" and "</dummy>". You can show this easily:

import java.io.*;
import java.util.*;
public class Test {
    public static void main(String[] args) throws IOException {
        Properties properties = new Properties();
        try (InputStream input = new FileInputStream("test.properties")) {
            properties.load(input);
        }

        for (String key : properties.stringPropertyNames()) {
            System.out.println(key + " = '" + properties.get(key) + "'");
        }
    }
}

This is at least somewhat indicated in the documentation with this part:

As a third example, the line:

cheeses

specifies that the key is "cheeses" and the associated element is the empty string "".

... but it's not as clearly written as it might be.

people

See more on this question at Stackoverflow