spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
55.28k stars 37.62k forks source link

Ignore non-String keys in `PropertiesPropertySource.getPropertyNames()` #32742

Closed tyt-gtdg closed 2 weeks ago

tyt-gtdg commented 2 weeks ago

System.getProperties().put(1,1);

2024-05-01 11:16:16.216 ERROR - [http-nio-55588-exec-2]  o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [org.apache.shiro.authc.AuthenticationException: error token] with root cause

java.lang.ArrayStoreException: java.lang.Integer
    at java.util.AbstractCollection.toArray(AbstractCollection.java:196) ~[na:1.8.0_301]
    at java.util.Collections$SynchronizedCollection.toArray(Collections.java:2029) ~[na:1.8.0_301]
    at org.springframework.util.StringUtils.toStringArray(StringUtils.java:924) ~[spring-core-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.core.env.MapPropertySource.getPropertyNames(MapPropertySource.java:60) ~[spring-core-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.core.env.PropertiesPropertySource.getPropertyNames(PropertiesPropertySource.java:51) ~[spring-core-5.2.10.RELEASE.jar:5.2.10.RELEASE]
    at org.springframework.cloud.netflix.archaius.ConfigurableEnvironmentConfiguration.getKeys(ConfigurableEnvironmentConfiguration.java:75) ~[spring-cloud-netflix-archaius-2.2.5.RELEASE.jar:2.2.5.RELEASE]
    at org.apache.commons.configuration.AbstractConfiguration.getKeys(AbstractConfiguration.java:574) ~[commons-configuration-1.8.jar:1.8]
    at com.netflix.config.ConcurrentCompositeConfiguration.getKeys(ConcurrentCompositeConfiguration.java:600) ~[archaius-core-0.7.6.jar:0.7.6]
    at org.apache.commons.configuration.SubsetConfiguration.getKeys(SubsetConfiguration.java:192) ~[commons-configuration-1.8.jar:1.8]
    at com.netflix.client.config.DefaultClientConfigImpl.loadProperties(DefaultClientConfigImpl.java:580) ~[ribbon-core-2.3.0.jar:2.3.0]
snicoll commented 2 weeks ago

@tyt-gtdg thanks for the report, but a line of code is not an actionable bug report. If you want support, please take the time to provide more details as your assumption is hiding more details that we need to investigate.

A sample application that reproduces the problem is ideal. You can attach a zip to this issue or push the code to a separate GitHub repository.

sbrannen commented 2 weeks ago

In addition, please note that Spring Framework 5.2.10.RELEASE is no longer supported.

In light of that, please upgrade to a supported version to see if the issue still exists.

jhoeller commented 2 weeks ago

@tyt-gtdg I suppose you'd expect Spring's PropertiesPropertySource to verify that it only contains Strings, or specifically for getPropertyNames to ignore non-String keys? Since we just wrap a target Map/Properties instance there, we cannot reject it - but we can make getPropertyNames leniently ignore non-String keys, just like java.util.Properties.stringPropertyNames() does.

tyt-gtdg commented 1 week ago

@tyt-gtdg thanks for the report, but a line of code is not an actionable bug report. If you want support, please take the time to provide more details as your assumption is hiding more details that we need to investigate.

A sample application that reproduces the problem is ideal. You can attach a zip to this issue or push the code to a separate GitHub repository.

static { System.getProperties().put(1,1); } public static void main(String[] args) { SpringApplication.run(SystemServerApplication.class, args); } If you start it the way above, You will see boot failure.

at org.springframework.util.StringUtils.toStringArray(StringUtils.java:954)

Collection genericity String

jhoeller commented 6 days ago

@tyt-gtdg indeed, and this should be fixed in the meantime. Feel free to give a recent 6.1.7 snapshot a try...