You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@commons.apache.org by Dave Westerman <dl...@comcast.net> on 2007/06/22 23:37:02 UTC
[commons-configuration] Variable Syntax Conflict
I am using the commons-configuration for my property files. However,
unfortunately, I have a need to have a value in some of my properties
that look exactly like the variables that commons-config uses.
myproperty=${myNonCommonsConfigVariable}
I've tried to escape it thus:
myproperty=\${myNonCommonsConfigVariable}
myproperty=\\${myNonCommonsConfigVariable}
myproperty=$${myNonCommonsConfigVariable}
but all to no avail.
Is there any way for me to get around this conflict? Can I change the
delimiter that commons-config uses (I've looked at all the classes,
there doesn't seem to be a way)?
The error I'm getting is this:
java.lang.IllegalStateException: infinite loop in property interpolation
of
${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar:
DB2UNIVERSAL_JDBC_DRIVER_PATH->DB2UNIVERSAL_JDBC_DRIVER_PATH
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [commons-configuration] Variable Syntax Conflict
Posted by Oliver Heger <ol...@oliver-heger.de>.
Dave Westerman wrote:
> Oliver, thanks for the info. I am indeed using release 1.3. And you're
> right, the $$ does escape the variable character, in some circumstances.
>
> I didn't get much time to work on this today, but when I changed it to
> only have one entry in the property that looks like a variable, it works
> okay:
> myproperty=$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar
>
> However, if I have multiple entries, that is when I am getting the error:
> myproperty=$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar,$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar
>
>
> I need to do some more testing, to see what combinations of this work
> and which ones don't. But thanks for giving me something to go on!
Is it possible that your problem is related to list parsing? (You have
the "," in your property value, which will be interpreted as list
delimiter per default, resulting in a property with multiple values.)
I have written a test case that looks roughly like this:
config.addProperty("mypath",
"$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar\\,$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar");
assertEquals("Wrong interpolated value",
"${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar",
config.getString("mypath"));
This works for me. Note that I escaped the "," character. (The test also
works if the "," is not escaped, but then only the first part of the
value string will be returned by getString().)
If you think there is a bug in the interpolation handling, please open a
ticket in our bug tracking system [1].
Thanks
Oliver
[1] http://jakarta.apache.org/commons/configuration/issue-tracking.html
>
> Oliver Heger wrote:
>> Hi Dave,
>>
>> which version of Commons Configuration do you use? Since the 1.3
>> release substituation of variables is handled by the StrSubstitutor
>> class of Commons Lang [1]. Here the '$' sign is used for escaping
>> variables, so your 3rd example
>>
>> myproperty=$${myNonCommonsConfigVariable}
>>
>> should work. There is also a unit test that checks this behavior:
>>
>> public void testInterpolationEscaped()
>> {
>> config.addProperty("var", "x");
>> config.addProperty("escVar", "Use the variable $${${var}}.");
>> assertEquals("Wrong escaped variable", "Use the variable
>> ${x}.", config
>> .getString("escVar"));
>> }
>>
>> IIRC in earlier versions of Configuration escaping variables was not
>> supported.
>>
>> Oliver
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: commons-user-help@jakarta.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [commons-configuration] Variable Syntax Conflict
Posted by Dave Westerman <dl...@comcast.net>.
Oliver, thanks for the info. I am indeed using release 1.3. And you're
right, the $$ does escape the variable character, in some circumstances.
I didn't get much time to work on this today, but when I changed it to
only have one entry in the property that looks like a variable, it works
okay:
myproperty=$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar
However, if I have multiple entries, that is when I am getting the error:
myproperty=$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar,$${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar
I need to do some more testing, to see what combinations of this work
and which ones don't. But thanks for giving me something to go on!
Oliver Heger wrote:
> Hi Dave,
>
> which version of Commons Configuration do you use? Since the 1.3
> release substituation of variables is handled by the StrSubstitutor
> class of Commons Lang [1]. Here the '$' sign is used for escaping
> variables, so your 3rd example
>
> myproperty=$${myNonCommonsConfigVariable}
>
> should work. There is also a unit test that checks this behavior:
>
> public void testInterpolationEscaped()
> {
> config.addProperty("var", "x");
> config.addProperty("escVar", "Use the variable $${${var}}.");
> assertEquals("Wrong escaped variable", "Use the variable
> ${x}.", config
> .getString("escVar"));
> }
>
> IIRC in earlier versions of Configuration escaping variables was not
> supported.
>
> Oliver
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org
Re: [commons-configuration] Variable Syntax Conflict
Posted by Oliver Heger <ol...@oliver-heger.de>.
Hi Dave,
Dave Westerman wrote:
> I am using the commons-configuration for my property files. However,
> unfortunately, I have a need to have a value in some of my properties
> that look exactly like the variables that commons-config uses.
>
> myproperty=${myNonCommonsConfigVariable}
>
> I've tried to escape it thus:
>
> myproperty=\${myNonCommonsConfigVariable}
> myproperty=\\${myNonCommonsConfigVariable}
> myproperty=$${myNonCommonsConfigVariable}
>
> but all to no avail.
>
> Is there any way for me to get around this conflict? Can I change the
> delimiter that commons-config uses (I've looked at all the classes,
> there doesn't seem to be a way)?
>
> The error I'm getting is this:
>
> java.lang.IllegalStateException: infinite loop in property interpolation
> of
> ${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cu.jar,${DB2UNIVERSAL_JDBC_DRIVER_PATH}/db2jcc_license_cisuz.jar:
> DB2UNIVERSAL_JDBC_DRIVER_PATH->DB2UNIVERSAL_JDBC_DRIVER_PATH
>
which version of Commons Configuration do you use? Since the 1.3 release
substituation of variables is handled by the StrSubstitutor class of
Commons Lang [1]. Here the '$' sign is used for escaping variables, so
your 3rd example
myproperty=$${myNonCommonsConfigVariable}
should work. There is also a unit test that checks this behavior:
public void testInterpolationEscaped()
{
config.addProperty("var", "x");
config.addProperty("escVar", "Use the variable $${${var}}.");
assertEquals("Wrong escaped variable", "Use the variable
${x}.", config
.getString("escVar"));
}
IIRC in earlier versions of Configuration escaping variables was not
supported.
Oliver
[1]
http://jakarta.apache.org/commons/lang/api-release/org/apache/commons/lang/text/StrSubstitutor.html
---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org