ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Shackelford, John-Mason" <>
Subject RE: loadproperties gotcha
Date Tue, 15 Oct 2002 15:32:48 GMT

> Both tasks use Properties#load(InputStream)

Ah, then this explains the behavior. When Ant loads a property file it is
just pulling key-value pairs out of a HashTable. When a property is
previously defined normal  substitution occurs so that: = foo = ${} bar

( is now 'foo bar')

I use this all the time to good effect and assumed that since I am seeing
normal ant substation a property that has already been set would not be
overridden. But the behaviour of HashTable is exactly opposite that of Ant:
subsequent key-value pairs always replace the former ones where an existing
key already exists. My first thought was then to suggest, for the sake of
consistency--on this admittedly minor point--that we simply override the
put() in a Properties subclass to mimic the behavior we expect from Ant.

Then it occurs to me this morning: if we are adding properties only after
having loaded the HashTable we have no guarantee that the properties are
truly added in the order specified by the property file, which seems odd to
me since it means I've been incredibly lucky in nearly 10k + lines of
buildfiles and scores of properties files I've written in the past six

I knew I had adopted the practice of property composition within property
files after having read something suggesting it. I didn't see anything in
the current docs about thiit though and I took a quick look through _Java
Tools for Extreme Programming_ and _Ant: The Definitive Guide_ but didn't
see it there either.

Then I found this scrap from a tomcat buildfile:

  You will note below that property values can be composed based on the
  contents of previously defined properties.  This is a powerful technique
  that helps you minimize the number of changes required when your
  environment is modified.  Note that property composition is allowed within
  "" files as well as in the "build.xml" script.

While one example hardly makes a case, it does seem to me that this is
something of an idiom, but unless I am being dense or have misunderstood you
it really isn't guaranteed to work the way we are accustomed to thinking
about it.

John-Mason Shackelford

Software Developer
NCS Pearson - Measurement Services
2510 North Dodge St.
Iowa City, IA 52245

-----Original Message-----
From: Stefan Bodewig [] 
Sent: Monday, October 07, 2002 5:46 AM
Subject: Re: loadproperties gotcha

On Fri, 4 Oct 2002, John-Mason Shackelford <> wrote:

> I need to look at the source to confirm, but it looks to me like 
> <loadproperties> does not behave as <property> in that when two 
> identical properties occur in the same file the last rather than the 
> first value is set.

Having looked at the source: you may be right or wrong 8-).

Both tasks your Properties#load(InputStream) and I'm not sure which one is
going to be added to the resulting Properties object if your properties file
contains the same key multiple times.  I don't think this is defined at all.


To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

This email may contain confidential material. 
If you were not an intended recipient, 
Please notify the sender and delete all copies. 
We may monitor email to and from our network. 

To unsubscribe, e-mail:   <>
For additional commands, e-mail: <>

View raw message