Skip to content

Fix: Added null safety check in NHM dashboard scheduler (#121)#367

Open
srilasya1815 wants to merge 1 commit intoPSMRI:mainfrom
srilasya1815:fix-nullpointer-startup
Open

Fix: Added null safety check in NHM dashboard scheduler (#121)#367
srilasya1815 wants to merge 1 commit intoPSMRI:mainfrom
srilasya1815:fix-nullpointer-startup

Conversation

@srilasya1815
Copy link

@srilasya1815 srilasya1815 commented Mar 3, 2026

Description

Added defensive null check for NHM_DashboardService in
ScheduleJobForNHMDashboardData to prevent potential
NullPointerException during scheduler execution after application startup.

Changes

  • Added null check before service invocation
  • Improved exception logging

This improves startup stability.

Closes #121

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling and validation for scheduled dashboard data processing to improve system reliability and prevent application interruptions.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 3, 2026

📝 Walkthrough

Walkthrough

The pull request includes formatting adjustments to pom.xml and improves error handling and logging in the ScheduleJobForNHMDashboardData class by adding a null-check for nhmDashboardService and enhancing exception logging and reporting.

Changes

Cohort / File(s) Summary
Configuration & Build
pom.xml
Formatting adjustments with additional blank lines around sections; no functional or dependency changes.
Scheduler Error Handling
src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java
Added null-check for nhmDashboardService to prevent execution when bean is uninitialized. Enhanced error logging with descriptive messages and stack traces. Improved execution start/completion logging.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~15 minutes

Poem

🐰 A scheduler hops with caution now,
Checking null before a vow,
Logs dance bright when things go wrong,
Error handling, strong and strong!
With formatting spruced, all clean,
The codebase's finest scene! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 3

❌ Failed checks (3 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The PR does not address the coding requirements in issue #121, which asks for face embedding functionality changes, but instead implements an unrelated null safety fix for the scheduler. Clarify whether issue #121 should reference null safety fixes or if this PR is linked to the wrong issue. The PR should implement the face embedding changes described in #121.
Out of Scope Changes check ⚠️ Warning The changes to add null safety checks in the scheduler are out of scope for issue #121, which focuses on face embedding functionality and associated feature improvements. Either link this PR to the correct issue related to scheduler null safety improvements, or refocus the PR on implementing the face embedding changes required by issue #121.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: adding a null safety check in the NHM dashboard scheduler, which is the primary focus of the changeset.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 3, 2026

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java (1)

50-60: Please add regression tests for the new control flow.

Add tests for (1) null nhmDashboardService skip path and (2) exception path from pull_NHM_Data_CTI() to lock in behavior.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java`
around lines 50 - 60, Add unit tests for ScheduleJobForNHMDashboardData to cover
both new control paths: create a test that sets the nhmDashboardService field to
null (or inject a null mock) and asserts that execute() returns/finishes without
calling any service methods and that logger.error("NHM_DashboardService bean is
not initialized. Skipping execution.") is invoked (use a logging/appenders test
helper or verify no interactions on a mocked service); and create a test that
injects a mock NHM_DashboardService where pull_NHM_Data_CTI() throws an
exception and assert execute() catches it and calls logger.error("Error while
pulling NHM dashboard data", e) (or verify exception handling behavior and that
no exception escapes). Target the ScheduleJobForNHMDashboardData class and the
nhmDashboardService field and pull_NHM_Data_CTI() method when wiring mocks and
assertions.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In
`@src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java`:
- Around line 55-62: The catch block in ScheduleJobForNHMDashboardData currently
swallows exceptions from nhmDashboardService.pull_NHM_Data_CTI() and always logs
completion; change it to rethrow a Quartz JobExecutionException so Quartz sees
failures: move the "Completed job..." logger into the try block (after
nhmDashboardService.pull_NHM_Data_CTI() and logger.info(s)), and in the
catch(Exception e) throw new JobExecutionException("Error pulling NHM dashboard
data for " + arg0.getClass().getName(), e, false) (or true if you want retry) so
the failure is propagated to Quartz.

---

Nitpick comments:
In
`@src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java`:
- Around line 50-60: Add unit tests for ScheduleJobForNHMDashboardData to cover
both new control paths: create a test that sets the nhmDashboardService field to
null (or inject a null mock) and asserts that execute() returns/finishes without
calling any service methods and that logger.error("NHM_DashboardService bean is
not initialized. Skipping execution.") is invoked (use a logging/appenders test
helper or verify no interactions on a mocked service); and create a test that
injects a mock NHM_DashboardService where pull_NHM_Data_CTI() throws an
exception and assert execute() catches it and calls logger.error("Error while
pulling NHM dashboard data", e) (or verify exception handling behavior and that
no exception escapes). Target the ScheduleJobForNHMDashboardData class and the
nhmDashboardService field and pull_NHM_Data_CTI() method when wiring mocks and
assertions.

ℹ️ Review info

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 4b44045 and efdbaf0.

📒 Files selected for processing (2)
  • pom.xml
  • src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java

Comment on lines +55 to +62
try {
String s = nhmDashboardService.pull_NHM_Data_CTI();
logger.info(s);
} catch (Exception e) {
logger.error("Error while pulling NHM dashboard data", e);
}

logger.info("Completed job for NHM dashboard data pull from cti " + arg0.getClass().getName());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🌐 Web query:

Quartz Scheduler Job execute method exception handling if exception caught and not thrown

💡 Result:

If your Quartz Job.execute(...) catches an exception and does not rethrow it, Quartz treats that run as successful: the trigger is considered “completed normally,” the scheduler won’t refire/unschedule based on that failure, and the job will simply run again at its next scheduled fire time. (Quartz only reacts when something escapes execute, especially a JobExecutionException.) [3], [4]

If you want Quartz to know the run failed and optionally take action, rethrow a JobExecutionException:

  • Keep normal schedule (no immediate refire, no unschedule): throw new JobExecutionException(cause) with no flags (it records the failure; next fire proceeds normally). [2], [5]
  • Refire immediately: new JobExecutionException(cause, refireImmediately: true) (Quartz.NET example shown; same concept in Java). [1], [2]
  • Unschedule triggers / stop future runs: set setUnscheduleAllTriggers(true) (Java example). [6], [2]

So: catch-and-swallow = Quartz won’t do anything special; catch-and-throw JobExecutionException = Quartz can apply retry/unschedule directives. [2], [6]


🏁 Script executed:

find . -name "ScheduleJobForNHMDashboardData.java" -type f

Repository: PSMRI/Common-API

Length of output: 141


🏁 Script executed:

cat -n ./src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java

Repository: PSMRI/Common-API

Length of output: 2757


Propagate job failures to Quartz instead of suppressing them.

Exceptions caught at lines 58–60 are logged but not re-thrown. Quartz treats this as a successful job execution (exceptions only matter to Quartz when JobExecutionException escapes execute()). Additionally, line 62 unconditionally logs completion even after a failure, obscuring actual failures in logs and monitoring.

Move the completion log into the try block and throw JobExecutionException on exception:

Proposed fix
 public void execute(JobExecutionContext arg0) throws JobExecutionException {

     logger.info("Started job for NHM dashboard data pull from cti " + arg0.getClass().getName());

     if (nhmDashboardService == null) {
         logger.error("NHM_DashboardService bean is not initialized. Skipping execution.");
         return;
     }

     try {
         String s = nhmDashboardService.pull_NHM_Data_CTI();
         logger.info(s);
+        logger.info("Completed job for NHM dashboard data pull from cti " + arg0.getClass().getName());
     } catch (Exception e) {
         logger.error("Error while pulling NHM dashboard data", e);
-    }
-
-    logger.info("Completed job for NHM dashboard data pull from cti " + arg0.getClass().getName());
+        throw new JobExecutionException("Error while pulling NHM dashboard data", e, false);
+    }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In
`@src/main/java/com/iemr/common/config/quartz/ScheduleJobForNHMDashboardData.java`
around lines 55 - 62, The catch block in ScheduleJobForNHMDashboardData
currently swallows exceptions from nhmDashboardService.pull_NHM_Data_CTI() and
always logs completion; change it to rethrow a Quartz JobExecutionException so
Quartz sees failures: move the "Completed job..." logger into the try block
(after nhmDashboardService.pull_NHM_Data_CTI() and logger.info(s)), and in the
catch(Exception e) throw new JobExecutionException("Error pulling NHM dashboard
data for " + arg0.getClass().getName(), e, false) (or true if you want retry) so
the failure is propagated to Quartz.

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