bito-code-review[bot] commented on PR #15956:
URL: https://github.com/apache/grails-core/pull/15956#issuecomment-4937668336
<!-- Bito Reply -->
The current implementation of `UrlMappingsIndexProperties.load(ClassLoader)`
prioritizes the provided classloader over the thread context classloader
(TCCL), which can prevent discovery of application-packaged resources.
Additionally, `Properties.load(InputStream)` can throw
`IllegalArgumentException` for malformed content, which is not currently
handled.
To address these issues, it is recommended to:
1. Update the `load` method to check the TCCL first, falling back to the
provided classloader if necessary.
2. Wrap both `IOException` and `IllegalArgumentException` in a consistent
exception type (e.g., `IllegalStateException`) to ensure robust error handling.
**grails-web-url-mappings/src/main/groovy/org/grails/web/mapping/UrlMappingsIndexProperties.java**
```
public static UrlMappingsIndexProperties load(ClassLoader classLoader) {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
if (loader == null) {
loader = classLoader;
}
if (loader == null) {
return EMPTY;
}
try (InputStream inputStream = loader.getResourceAsStream(LOCATION))
{
if (inputStream == null) {
return EMPTY;
}
Properties properties = new Properties();
properties.load(inputStream);
return new UrlMappingsIndexProperties(true, properties);
}
catch (IOException | IllegalArgumentException e) {
throw new IllegalStateException("Unable to load " + LOCATION, e);
}
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]