Skip to content

Optimize ObjectMapper Configuration in Exception Handlers#1799

Open
zealot-zew wants to merge 1 commit intomosip:masterfrom
zealot-zew:fix/javatimemodule-registration-on-startup
Open

Optimize ObjectMapper Configuration in Exception Handlers#1799
zealot-zew wants to merge 1 commit intomosip:masterfrom
zealot-zew:fix/javatimemodule-registration-on-startup

Conversation

@zealot-zew
Copy link
Copy Markdown

Summary

This PR fixes a performance and thread-safety issue where JavaTimeModule was being redundantly registered on a shared ObjectMapper instance during every error response generation.

Problem

In both EmailNotificationApiExceptionHandler and ApiExceptionalHandler, the setErrors() method was calling objectMapper.registerModule(new JavaTimeModule()). Since the ObjectMapper is an @Autowired singleton:

  • Redundancy: The module was re-registered on every single API error, wasting CPU cycles.
  • Thread Safety: Modifying the state of a shared singleton during request processing is not thread-safe and can lead to inconsistent behavior.

Changes

  • Files: EmailNotificationApiExceptionHandler.java, ApiExceptionalHandler.java
  • Action: Removed the registration logic from the request-scoped setErrors() method.
  • Action: Introduced a @PostConstruct method to register the JavaTimeModule exactly once when the bean is initialized.

Impact

  • Performance: Reduces overhead during exception handling by eliminating redundant configuration logic.
  • Stability: Ensures the shared ObjectMapper is configured in a thread-safe manner during application startup rather than at runtime.

Signed-off-by: Harihara Vardhan <hariharavardhan1234@gmail.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 25, 2026

Warning

Rate limit exceeded

@zealot-zew has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 16 minutes and 0 seconds before requesting another review.

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 16 minutes and 0 seconds.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 3b3cc286-fb33-4052-83db-4b8d76651b23

📥 Commits

Reviewing files that changed from the base of the PR and between c30080f and a2ed4f7.

📒 Files selected for processing (2)
  • kernel/kernel-notification-service/src/main/java/io/mosip/kernel/emailnotification/exception/EmailNotificationApiExceptionHandler.java
  • kernel/kernel-ridgenerator-service/src/main/java/io/mosip/kernel/ridgenerator/exception/ApiExceptionalHandler.java
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@zealot-zew
Copy link
Copy Markdown
Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Apr 26, 2026

Only users with a collaborator, contributor, member, or owner role can interact with CodeRabbit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant