Add null check before removing sub-sub-attribute#458
Add null check before removing sub-sub-attribute#458AfraHussaindeen merged 1 commit intowso2:masterfrom
Conversation
| Attribute parent = ((ComplexAttribute) grandParent).getSubAttribute(parentAttribute); | ||
| ((ComplexAttribute) (parent)).removeSubAttribute(childAttribute); | ||
|
|
||
| if (parent != null) { | ||
| ((ComplexAttribute) (parent)).removeSubAttribute(childAttribute); | ||
| } | ||
| } |
There was a problem hiding this comment.
Log Improvement Suggestion No: 1
| Attribute parent = ((ComplexAttribute) grandParent).getSubAttribute(parentAttribute); | |
| ((ComplexAttribute) (parent)).removeSubAttribute(childAttribute); | |
| if (parent != null) { | |
| ((ComplexAttribute) (parent)).removeSubAttribute(childAttribute); | |
| } | |
| } | |
| Attribute parent = ((ComplexAttribute) grandParent).getSubAttribute(parentAttribute); | |
| if (parent != null) { | |
| log.debug("Removing sub-attribute '{}' from parent attribute '{}'.", childAttribute, parentAttribute); | |
| ((ComplexAttribute) (parent)).removeSubAttribute(childAttribute); | |
| } else { | |
| log.warn("Parent attribute '{}' not found in grandparent '{}'. Cannot remove child attribute '{}'.", parentAttribute, grandParentAttribute, childAttribute); | |
| } |
There was a problem hiding this comment.
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.
| Comment | Accepted (Y/N) | Reason |
|---|---|---|
| #### Log Improvement Suggestion No: 1 |
WalkthroughA null-check guard is added to the Changes
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java (1)
162-177: Consider applying similar null-check todeleteSubValuesSubAttribute.For consistency and robustness,
deleteSubValuesSubAttributehas the same potential NPE at line 168 wheresubAttributeList.get(parentAttribute)could return null. You may want to address this in a follow-up.♻️ Optional fix for similar vulnerability
public void deleteSubValuesSubAttribute(String grandParentAttribute, String parentAttribute, String subValue, String childAttribute) { if (attributeList.containsKey(grandParentAttribute)) { ComplexAttribute grandParent = (ComplexAttribute) attributeList.get(grandParentAttribute); Map<String, Attribute> subAttributeList = grandParent.getSubAttributesList(); MultiValuedAttribute parent = (MultiValuedAttribute) subAttributeList.get(parentAttribute); + if (parent == null) { + return; + } List<Attribute> parentAttributeList = parent.getAttributeValues(); for (Attribute parentsSubValue : parentAttributeList) { if (subValue.equals(parentsSubValue.getName())) { ((ComplexAttribute) parentsSubValue).removeSubAttribute(childAttribute); } } } }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java` around lines 162 - 177, The method deleteSubValuesSubAttribute can NPE when subAttributeList.get(parentAttribute) returns null; update deleteSubValuesSubAttribute to null-check the retrieved parent MultiValuedAttribute (and its attribute values) before using it: after obtaining subAttributeList and assigning parent (MultiValuedAttribute parent = ...), if parent is null return/exit the method, and likewise check parent.getAttributeValues() for null before iterating over parentAttributeList; reference symbols: attributeList, ComplexAttribute grandParent, subAttributeList, parent (MultiValuedAttribute), parentAttributeList, and removeSubAttribute(childAttribute).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In
`@modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java`:
- Around line 162-177: The method deleteSubValuesSubAttribute can NPE when
subAttributeList.get(parentAttribute) returns null; update
deleteSubValuesSubAttribute to null-check the retrieved parent
MultiValuedAttribute (and its attribute values) before using it: after obtaining
subAttributeList and assigning parent (MultiValuedAttribute parent = ...), if
parent is null return/exit the method, and likewise check
parent.getAttributeValues() for null before iterating over parentAttributeList;
reference symbols: attributeList, ComplexAttribute grandParent,
subAttributeList, parent (MultiValuedAttribute), parentAttributeList, and
removeSubAttribute(childAttribute).
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 095c5091-467f-4436-92a9-db3b1ca2d60f
📒 Files selected for processing (1)
modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java
Codecov Report❌ Patch coverage is
❌ Your patch status has failed because the patch coverage (0.00%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #458 +/- ##
============================================
- Coverage 31.93% 31.93% -0.01%
Complexity 1112 1112
============================================
Files 137 137
Lines 13524 13525 +1
Branches 2589 2590 +1
============================================
Hits 4319 4319
- Misses 8667 8668 +1
Partials 538 538
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:
|
Purpose
Summary by CodeRabbit