-
Notifications
You must be signed in to change notification settings - Fork 87
Harden enum parsing with null-safe, case-insensitive resolution and consistent validation #592
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Harden enum parsing with null-safe, case-insensitive resolution and consistent validation #592
Conversation
…onsistent validation
...arbon/identity/organization/management/organization/user/sharing/constant/EditOperation.java
Show resolved
Hide resolved
...2/carbon/identity/organization/management/organization/user/sharing/constant/SharedType.java
Outdated
Show resolved
Hide resolved
...tity/organization/management/organization/user/sharing/constant/UserSharePatchOperation.java
Outdated
Show resolved
Hide resolved
...bon/identity/organization/resource/sharing/policy/management/constant/OrganizationScope.java
Show resolved
Hide resolved
...bon/identity/organization/resource/sharing/policy/management/constant/OrganizationScope.java
Show resolved
Hide resolved
...n/identity/organization/resource/sharing/policy/management/constant/SharedAttributeType.java
Show resolved
Hide resolved
...n/identity/organization/resource/sharing/policy/management/constant/SharedAttributeType.java
Show resolved
Hide resolved
There was a problem hiding this 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
- 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.
There was a problem hiding this 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/fromValuemethods to all relevant enums with null-safe, case-insensitive matching - Enhanced existing enum lookup methods in
PolicyEnumto 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 |
...so2/carbon/identity/organization/resource/sharing/policy/management/constant/PolicyEnum.java
Outdated
Show resolved
Hide resolved
...so2/carbon/identity/organization/resource/sharing/policy/management/constant/PolicyEnum.java
Outdated
Show resolved
Hide resolved
...2/carbon/identity/organization/resource/sharing/policy/management/constant/ResourceType.java
Outdated
Show resolved
Hide resolved
...tity/organization/management/organization/user/sharing/constant/UserSharePatchOperation.java
Outdated
Show resolved
Hide resolved
...2/carbon/identity/organization/management/organization/user/sharing/constant/SharedType.java
Outdated
Show resolved
Hide resolved
...so2/carbon/identity/organization/resource/sharing/policy/management/constant/PolicyEnum.java
Outdated
Show resolved
Hide resolved
...so2/carbon/identity/organization/resource/sharing/policy/management/constant/PolicyEnum.java
Show resolved
Hide resolved
...n/identity/organization/resource/sharing/policy/management/constant/SharedAttributeType.java
Outdated
Show resolved
Hide resolved
...bon/identity/organization/resource/sharing/policy/management/constant/OrganizationScope.java
Outdated
Show resolved
Hide resolved
...arbon/identity/organization/management/organization/user/sharing/constant/EditOperation.java
Outdated
Show resolved
Hide resolved
Codecov Report✅ All modified and coverable lines are covered by tests. 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
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
PR builder started |
|
PR builder completed |
|
PR builder started |
|
PR builder completed |
jenkins-is-staging
left a comment
There was a problem hiding this 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
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
nulland empty values.Approach
fromString/fromValue/ lookup methods to relevant enums.Related PRs
Related Issues