Skip to content

Conversation

@BimsaraBodaragama
Copy link
Contributor

@BimsaraBodaragama BimsaraBodaragama commented Dec 22, 2025

Purpose

Improve robustness and API safety by making all enum resolution logic null-safe, case-insensitive, and predictable, preventing accidental NullPointerExceptions and unintended HTTP 500 errors when handling invalid or missing input.

Goals

  • Ensure all enum lookup and validation paths safely handle null and empty values.
  • Provide consistent, client-friendly error messages for invalid enum inputs.
  • Align enum parsing behavior across User Sharing and Resource Sharing policy components.

Approach

  • Added centralized, null-safe fromString / fromValue / lookup methods to relevant enums.
  • Normalized input handling using trimming and case-insensitive comparisons.
  • Precomputed valid enum identifiers to avoid repeated allocations and improve error clarity.
  • Made enum-held collections defensively unmodifiable where applicable.
  • Kept existing enum constants and public behavior intact while hardening validation paths.

Related PRs

Related Issues

@BimsaraBodaragama BimsaraBodaragama self-assigned this Dec 22, 2025
Copy link

@wso2-engineering wso2-engineering bot left a comment

Choose a reason for hiding this comment

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

AI Agent Log Improvement Checklist

⚠️ Warning: AI-Generated Review Comments

  • The log-related comments and suggestions in this review were generated by an AI tool to assist with identifying potential improvements. Purpose of reviewing the code for log improvements is to improve the troubleshooting capabilities of our products.
  • Please make sure to manually review and validate all suggestions before applying any changes. Not every code suggestion would make sense or add value to our purpose. Therefore, you have the freedom to decide which of the suggestions are helpful.

✅ Before merging this pull request:

  • Review all AI-generated comments for accuracy and relevance.
  • Complete and verify the table below. We need your feedback to measure the accuracy of these suggestions and the value they add. If you are rejecting a certain code suggestion, please mention the reason briefly in the suggestion for us to capture it.
Comment Accepted (Y/N) Reason
#### Log Improvement Suggestion No: 1 N #592 (comment)
#### Log Improvement Suggestion No: 2 N #592 (comment)
#### Log Improvement Suggestion No: 3 N #592 (comment)
#### Log Improvement Suggestion No: 4 N #592 (comment)
#### Log Improvement Suggestion No: 5 N #592 (comment)
#### Log Improvement Suggestion No: 6 N #592 (comment)
#### Log Improvement Suggestion No: 7 N #592 (comment)

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 hardens enum parsing across organization management components by introducing null-safe, case-insensitive resolution methods with comprehensive validation. The changes prevent NullPointerExceptions and improve API safety by ensuring all enum lookups consistently handle null, empty, and invalid inputs with clear error messages.

Key changes:

  • Added centralized fromString/fromValue methods to all relevant enums with null-safe, case-insensitive matching
  • Enhanced existing enum lookup methods in PolicyEnum to be null-safe with trimming and case-insensitive comparisons
  • Made enum-held collections defensively unmodifiable in ResourceType

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 11 comments.

Show a summary per file
File Description
SharedAttributeType.java Added null-safe fromString method with case-insensitive matching and precomputed valid types for error messages
ResourceType.java Added null-safe fromString method and made applicableAttributes defensively unmodifiable
PolicyEnum.java Enhanced existing lookup methods (getByPolicyCode, getByValue, validateAndGetPolicyEnum, etc.) with null-safety, trimming, and case-insensitive matching; precomputed valid values for error messages
OrganizationScope.java Added null-safe fromString method with case-insensitive matching and precomputed valid scopes
UserSharePatchOperation.java Enhanced fromValue method with null-safety, case-insensitive matching, and precomputed valid operations
SharedType.java Enhanced fromString method with null-safety, trimming, and precomputed valid types
RoleAssignmentMode.java Enhanced fromString method with null-safety, trimming, and precomputed valid modes
EditOperation.java Added null-safe fromString method with case-insensitive matching and precomputed valid operations

@codecov
Copy link

codecov bot commented Dec 22, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 53.24%. Comparing base (ec345d9) to head (894282c).
⚠️ Report is 3 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff              @@
##               main     #592      +/-   ##
============================================
- Coverage     54.72%   53.24%   -1.48%     
+ Complexity     2167     2157      -10     
============================================
  Files           215      213       -2     
  Lines         13020    13302     +282     
  Branches       2244     2186      -58     
============================================
- Hits           7125     7083      -42     
- Misses         5198     5535     +337     
+ Partials        697      684      -13     
Flag Coverage Δ
unit 38.34% <ø> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/20450427230

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/20450427230
Status: failure

@jenkins-is-staging
Copy link

PR builder started
Link: https://github.com/wso2/product-is/actions/runs/20453169227

@jenkins-is-staging
Copy link

PR builder completed
Link: https://github.com/wso2/product-is/actions/runs/20453169227
Status: success

Copy link

@jenkins-is-staging jenkins-is-staging left a comment

Choose a reason for hiding this comment

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

Approving the pull request based on the successful pr build https://github.com/wso2/product-is/actions/runs/20453169227

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.

3 participants