-
Notifications
You must be signed in to change notification settings - Fork 148
Refactor: Optimize AntPathMatcher usage, eliminate code duplication, and improve logging #5016
Description
Environment
Jmix version: 2.x (main branch)
Description
This is a code quality improvement proposal addressing three minor issues found in the codebase:
1. Inefficient AntPathMatcher instantiation
AntPathMatcher is instantiated on every method call in RestAuthorizedUrlsRequestMatcher, ReportAsResourceServerBeforeInvocationEventListener, and ReportOidcResourceServerBeforeInvocationEventListener. Since AntPathMatcher is stateless and thread-safe, it should be a static final field.
2. Code duplication in reports-rest module
ReportAsResourceServerBeforeInvocationEventListener and ReportOidcResourceServerBeforeInvocationEventListener contain nearly identical code. There is even a TODO comment in the code: "TODO get rid of code duplication".
3. Inefficient logging with string concatenation
Several classes use string concatenation in log statements (e.g., log.error("Message " + variable)) instead of SLF4J placeholders (log.error("Message {}", variable)). This causes unnecessary string concatenation even when the log level is disabled.
Current Behavior
- New
AntPathMatcherobject created on each request - Duplicated code in two event listeners
- String concatenation performed regardless of log level
Expected Behavior
- Single shared
AntPathMatcherinstance per class - Common logic extracted to abstract base class
- SLF4J parameterized logging for better performance
Proposed Solution
I have prepared a PR with the following changes:
- Extract
AntPathMatchertostatic finalfields - Create
AbstractReportBeforeInvocationEventListenerbase class - Replace string concatenation with
{}placeholders in 8 files
All existing tests pass.