Skip to content

Refactor: Optimize AntPathMatcher usage, eliminate code duplication, and improve logging #5016

@VladimirKozulin

Description

@VladimirKozulin

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 AntPathMatcher object created on each request
  • Duplicated code in two event listeners
  • String concatenation performed regardless of log level

Expected Behavior

  • Single shared AntPathMatcher instance 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 AntPathMatcher to static final fields
  • Create AbstractReportBeforeInvocationEventListener base class
  • Replace string concatenation with {} placeholders in 8 files

All existing tests pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions