[ 
https://issues.apache.org/jira/browse/CONFIGURATION-831?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17725817#comment-17725817
 ] 

Wojtek commented on CONFIGURATION-831:
--------------------------------------

Maybe it's just my impression and probably "should return empty string" would 
be better. My train of though, let's assume this config:

```xml

<configuration>
    <empty></empty>
    <env>${env:VARIABLE}</env>
</configuration>

```

 

a) config.getString("empty") -> will `yield` empty string (`""`)

b) config.getString("nosuchproperty") -> will yield `null`

 

Now, for the "env":

1. if we have `VARIABLE="bla"`, config.getString("env") will yield "bla" (as 
expected)

2. if we have variable set but without value (`VARIABLE=`), 
config.getString("env") will yield empty string (`""`) (somewhat as expected I 
guess)

3. if we don't have variable set, config.getString("env") will yield 
`"${env:VARIABLE}"`.

 

In the last case `${env:VARIABLE}` would evaluate to null/"", and then 
considering (a), my impression/expectation would be it should yield empty 
string as well.

> Unresolved (non-existend) environment variables should return null
> ------------------------------------------------------------------
>
>                 Key: CONFIGURATION-831
>                 URL: https://issues.apache.org/jira/browse/CONFIGURATION-831
>             Project: Commons Configuration
>          Issue Type: New Feature
>          Components: Interpolation
>    Affects Versions: 2.9.0
>            Reporter: Wojtek
>            Priority: Minor
>
> Currently Interpolation of environment variables 
> (https://commons.apache.org/proper/commons-configuration/userguide/howto_basicfeatures.html#Variable_Interpolation)
>  return un-interpolated string if the environment variable doesn't exists at 
> all.
> It would be very convenient and (I feel) more consistent if, in that case, 
> 'null' would be returned.
>  
> Alternatively, option to specify default if the variable doesn't exist would 
> also work.
> I.e. something along the lines:
> ```
> ${env:JAVA_HOME:<default value>}
> ```
>  
> From my experiments, even if we try to register custom interpolator it's not 
> possible to explicitly return `null` from it.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to