Name: dbT83986 Date: 03/09/99
=20
I am resubmitting this bug as it was previously evaluated and
concluded 'not a bug', when it obviously is.
java.util.Properties.load() does not ignore lines containing
whitespace. If a file has a line with whitespace, and you
load() that file into a properties object, then the properties
object will contain a property with an empty key and value.
Clarification: by 'empty' I mean - new String("")
Code illustrating this follows:
-------------------------------------------------
import java.io.*;
import java.util.Properties;
public class Test
{
public static void main(String []args)
{
Properties prop;
try {
// create test file
File file =3D new File("test.properties");
// write a single space to the test file
FileOutputStream fos =3D new FileOutputStream(file);
fos.write(' ');
fos.close();
// test empty properties
prop =3D new Properties();
System.out.println("empty properties follows");
System.out.println(prop);
// now load the file we just created, into a
// properties object.
// the properties object should have no elements,
// but due to a bug, it has an empty key/value.
// key =3D "", value =3D ""
prop =3D new Properties();
InputStream is =3D new FileInputStream(file);
prop.load(is);
System.out.println("properties loaded from file "+
"containing a single space");
System.out.println(prop);
// cleanup
file.delete();
}
catch(IOException e) {}
}
}
-------------------------------------------------
Included below is a copy of the email I sent in reply to the
initial evaluation by Gregory Stone. This was sent two weeks
ago, and as I have not received a reply, I am resubmitting
the bug.
--
Gregory Stone wrote:
>=20
> This is not a bug. The spec clearly states that "if a property name does
> not have a corresponding value, the result is as if the property does not
> exist."
I could not find that in the spec, but if it is indeed part of the spec,
then the implementation does not conform. A simple test shows that a
file consisting of single property name, e.g. the String "Truth", when
loaded into a Properties object will result in the property being stored
as a key "Truth", and value of the empty string "". This does not to me,
correspond with "the result is as if the property does not exist".
> This is in the paragraph AFTER it specifies that among the prohibited
> values for a property name is a space.
Where does it state this in the spec? I am looking at the spec at the
following URL, and I could not find anything to that effect.
http://java.sun.com/docs/books/jls/html/javautil.doc6.html#23061
> I suppose it doesn't make much sense for the property object to conatain =
a
> null key and a null value, but since you couldn't access it anyway (hence
> the phrase 'does not exist') it really doesn't effect anything. We are
> looking at other possible ways to handle a nul/null scenario, but thus fa=
r
> the tradesoffs (such as stricter requirements for property file contents
> and order of text) don't warrant the change just to prevent a null entry.
The property object does not contain a null key and a null value. It
contains a key being the empty string "", and a value being the empty
string "".
This is different to a null value. The empty string is equivalent to
doing new String("") which will create an object.
This behaviour does affect things. For example, I can no longer get a
correct count of the number of properties stored in the Properties object,
by invoking the size() method. To obtain the number of keys, I need to
manually iterate through the properties, only incrementing a counter when t=
he
key is not the empty string.
According to the spec at paragraph 21.6.7
http://java.sun.com/docs/books/jls/html/javautil.doc6.html#23061
A line that contains only whitespace (=A720.5.19) or whose first
non-whitespace character is an ASCII # or ! is ignored (thus,
# or ! indicate comment lines).
So if I interpret this correctly, a line containing a single space characte=
r,
as described in my original bug report, matches the above paragraph, and
should be ignored. It should *not* generate a property with empty key,
and empty value.
I believe, as I stated in my original bug report, that the behaviour that
is observed, IS a bug, and needs to be fixed. Please change the state of
this bug report from closed, to open.
Any further questions, please feel free to contact me.
Dion Mendel.
(Review ID: 55044)
======================================================================