Skip to content

Comments

fix: handle null employee role in leave admin check#1082

Merged
ThinuwanW merged 1 commit intodevelopfrom
fix/resource-calender-role-issue
Feb 20, 2026
Merged

fix: handle null employee role in leave admin check#1082
ThinuwanW merged 1 commit intodevelopfrom
fix/resource-calender-role-issue

Conversation

@akilarootcode
Copy link
Contributor

PR checklist

TaskId: (https://github.com/SkappHQ/skapp/issues/[id])

Summary

How to test

Project Checklist

  • Changes build without any errors
  • Have written adequate test cases
  • Done developer testing in
    • Chrome
    • Firefox
    • Safari
  • Code is formatted with npm run format
  • Code is linted with npm run check-lint
  • No unnecessary comments left in code
  • Made corresponding changes to the documentation

Other

  • New atomic components added
  • New molecules added
  • New pages(routes) added
  • New dependencies installed

PR Checklist

  • Pull request is raised from the correct source branch
  • Pull request is raised to the correct destination branch
  • Pull request is raised with correct title
  • Pull request is self reviewed
  • Pull request is self assigned
  • Suitable pull request status labels are added (ready-for-code-review)

Additional Information

@akilarootcode akilarootcode self-assigned this Feb 20, 2026
Copilot AI review requested due to automatic review settings February 20, 2026 06:48
@sonarqubecloud
Copy link

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses a null pointer exception bug by adding null safety checks when accessing the leaveRole field from EmployeeRole objects. The fix prevents potential crashes when an employee's leave role is not set.

Changes:

  • Added null checks before calling getLeaveRole().equals() in three locations across two service implementation files
  • Changed from direct equality check to a two-step check: first verifying the role is not null, then performing the equality comparison

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.

File Description
LeaveServiceImpl.java Added null check for leaveRole in getResourceAvailabilityCalendar method
LeaveAnalyticsServiceImpl.java Added null checks for leaveRole in getEmployeesOnLeave and getOrganizationalAbsenceRate methods

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

* @param requestedAnalytics requested analytics
*/
private void isEmployeeUnderCurrentUserSupervision(User currentUser, Employee employee, String requestedAnalytics) {
String currentUserRole = currentUser.getEmployee().getEmployeeRole().getLeaveRole().toString();
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The getLeaveRole() method is called without null safety check. This can lead to a NullPointerException if leaveRole is null. Consider adding a null check similar to the pattern used in the fixed locations.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this null scenario comes only for guest user apis

* @param requestedAnalytics requested analytics
*/
private void isTeamUnderCurrentUserSupervision(User currentUser, Team team, String requestedAnalytics) {
String currentUserRole = currentUser.getEmployee().getEmployeeRole().getLeaveRole().toString();
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The getLeaveRole() method is called without null safety check. This can lead to a NullPointerException if leaveRole is null. Consider adding a null check similar to the pattern used in the fixed locations.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this null scenario comes only for guest user apis

throw new EntityNotFoundException(PeopleMessageConstant.PEOPLE_ERROR_EMPLOYEE_NOT_FOUND);
}

Role leaveRole = currentUser.getEmployee().getEmployeeRole().getLeaveRole();
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The getLeaveRole() method is called without null safety check. This can lead to a NullPointerException if leaveRole is null. Consider adding a null check or using Optional.ofNullable() pattern as done in AuthorityServiceImpl.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this null scenario comes only for guest user apis


private boolean isUserSuperAdminOrLeaveAdmin(User user) {
EmployeeRole role = user.getEmployee().getEmployeeRole();
return role.getIsSuperAdmin() || Role.LEAVE_ADMIN.equals(role.getLeaveRole());
Copy link

Copilot AI Feb 20, 2026

Choose a reason for hiding this comment

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

The getLeaveRole() method is called without null safety check. This can lead to a NullPointerException if leaveRole is null. Consider adding a null check similar to the pattern used elsewhere in this file at line 730.

Copilot uses AI. Check for mistakes.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this null scenario comes only for guest user apis

@ThinuwanW ThinuwanW merged commit d056f6b into develop Feb 20, 2026
7 of 8 checks passed
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.

2 participants