refactor: log dynamic-theme initialization#144
Conversation
WalkthroughDynamicThemeInitializer is updated to discover and apply themes from multiple META-INF/dynamic-theme.properties resources via the class loader, replacing single-resource loading. Helper methods for URL parsing and theme reading are added alongside logging to track theme application sources. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In
`@src/main/java/com/flowingcode/vaadin/addons/demo/DynamicThemeInitializer.java`:
- Around line 50-57: The readTheme method currently returns empty silently when
the "theme" property is missing or invalid; update readTheme to (1) after
loading props check if props.getProperty("theme") is null or blank and log a
warning including the URL to indicate a misconfigured dynamic-theme.properties,
and (2) when mapping to DynamicTheme via DynamicTheme.valueOf, catch
IllegalArgumentException, log an error mentioning the invalid value and the URL,
and return Optional.empty; use the class logger (e.g., LOGGER or logger) for
these messages and keep the method signature and stream handling as-is.
| private Optional<DynamicTheme> readTheme(URL url) throws IOException { | ||
| try (InputStream in = url.openStream()) { | ||
| Properties props = new Properties(); | ||
| props.load(in); | ||
| String themeName = props.getProperty("theme"); | ||
| return Optional.ofNullable(themeName).map(String::trim).map(DynamicTheme::valueOf); | ||
| } | ||
| } |
There was a problem hiding this comment.
Silent skip when theme property is missing from a discovered file.
If a dynamic-theme.properties file is found but doesn't contain the theme key (e.g., typo like themes=LUMO), readTheme returns an empty Optional and nothing is logged. Given that this class now explicitly scans for these files, a missing property is likely a configuration error and should at least be logged as a warning.
Proposed fix
private Optional<DynamicTheme> readTheme(URL url) throws IOException {
try (InputStream in = url.openStream()) {
Properties props = new Properties();
props.load(in);
String themeName = props.getProperty("theme");
+ if (themeName == null || themeName.trim().isEmpty()) {
+ logger.warn("No 'theme' property found in {}", url);
+ return Optional.empty();
+ }
- return Optional.ofNullable(themeName).map(String::trim).map(DynamicTheme::valueOf);
+ return Optional.of(DynamicTheme.valueOf(themeName.trim()));
}
}🤖 Prompt for AI Agents
In
`@src/main/java/com/flowingcode/vaadin/addons/demo/DynamicThemeInitializer.java`
around lines 50 - 57, The readTheme method currently returns empty silently when
the "theme" property is missing or invalid; update readTheme to (1) after
loading props check if props.getProperty("theme") is null or blank and log a
warning including the URL to indicate a misconfigured dynamic-theme.properties,
and (2) when mapping to DynamicTheme via DynamicTheme.valueOf, catch
IllegalArgumentException, log an error mentioning the invalid value and the URL,
and return Optional.empty; use the class logger (e.g., LOGGER or logger) for
these messages and keep the method signature and stream handling as-is.



Log the resolved path of dynamic-theme.properties to identify and troubleshoot classpath conflicts caused by downstream dependencies.
Summary by CodeRabbit