[ 
https://issues.apache.org/jira/browse/JSPWIKI-1319?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Arturo Bernal updated JSPWIKI-1319:
-----------------------------------
    Description: 
PropertyReader.loadWebAppProps() ignores every jspwiki.* Java system property 
passed with -D.

The system properties are collected with Collectors.toMap( Object::toString, 
Object::toString ) over System.getProperties().entrySet(). Object::toString on 
a Map.Entry returns "key=value", so both the key and the value of the resulting 
map are "key=value". collectPropertiesFrom() then keeps the entry because the 
string starts with "jspwiki", but the property is stored under the key 
"jspwiki.foo=bar" and never under "jspwiki.foo".

Measured on master with a unit test: System.setProperty( 
"jspwiki.test.systemProperty", "fromSystem" ), then 
PropertyReader.loadWebAppProps( mock( ServletContext.class ) ); 
props.getProperty( "jspwiki.test.systemProperty" ) returns null (expected 
"fromSystem"). The same effect was seen in a running instance (Tomcat 10.1, JDK 
17) with a jspwiki.* property passed with -D: the properties contained the key 
"jspwiki.<name>=<value>" and the code that reads the property did not see the 
value. The same property set in a custom properties file or as an environment 
variable works.

Using System.getProperties().stringPropertyNames() with System::getProperty as 
the value fixes it; the test above then passes, as do the 8 tests of 
PropertyReaderTest.

  was:
PropertyReader.loadWebAppProps() ignores every jspwiki.* Java system property 
passed with -D.

The system properties are collected with Collectors.toMap( Object::toString, 
Object::toString ) over System.getProperties().entrySet(). Object::toString on 
a Map.Entry returns "key=value", so both the key and the value of the resulting 
map are "key=value". collectPropertiesFrom() then keeps the entry because the 
string starts with "jspwiki", but the property is stored under the key 
"jspwiki.foo=bar" and never under "jspwiki.foo".

Measured on master with a unit test: System.setProperty( 
"jspwiki.test.systemProperty", "fromSystem" ), then 
PropertyReader.loadWebAppProps( mock( ServletContext.class ) ); 
props.getProperty( "jspwiki.test.systemProperty" ) returns null (expected 
"fromSystem"). The same effect was seen in a running instance (Tomcat 10.1, JDK 
17): with -Djspwiki.http.filters.csrf.servletWhitelist=/sharetest the 
properties contained the key 
"jspwiki.http.filters.csrf.servletWhitelist=/sharetest" and the filter did not 
see the value. The same property set in a custom properties file or as an 
environment variable works.

Using System.getProperties().stringPropertyNames() with System::getProperty as 
the value fixes it; the test above then passes, as do the 8 tests of 
PropertyReaderTest.


> PropertyReader ignores jspwiki.* system properties passed with -D
> -----------------------------------------------------------------
>
>                 Key: JSPWIKI-1319
>                 URL: https://issues.apache.org/jira/browse/JSPWIKI-1319
>             Project: JSPWiki
>          Issue Type: Bug
>            Reporter: Arturo Bernal
>            Priority: Major
>              Labels: pull-request-available
>
> PropertyReader.loadWebAppProps() ignores every jspwiki.* Java system property 
> passed with -D.
> The system properties are collected with Collectors.toMap( Object::toString, 
> Object::toString ) over System.getProperties().entrySet(). Object::toString 
> on a Map.Entry returns "key=value", so both the key and the value of the 
> resulting map are "key=value". collectPropertiesFrom() then keeps the entry 
> because the string starts with "jspwiki", but the property is stored under 
> the key "jspwiki.foo=bar" and never under "jspwiki.foo".
> Measured on master with a unit test: System.setProperty( 
> "jspwiki.test.systemProperty", "fromSystem" ), then 
> PropertyReader.loadWebAppProps( mock( ServletContext.class ) ); 
> props.getProperty( "jspwiki.test.systemProperty" ) returns null (expected 
> "fromSystem"). The same effect was seen in a running instance (Tomcat 10.1, 
> JDK 17) with a jspwiki.* property passed with -D: the properties contained 
> the key "jspwiki.<name>=<value>" and the code that reads the property did not 
> see the value. The same property set in a custom properties file or as an 
> environment variable works.
> Using System.getProperties().stringPropertyNames() with System::getProperty 
> as the value fixes it; the test above then passes, as do the 8 tests of 
> PropertyReaderTest.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to