Skip to content

Add null check before removing sub-sub-attribute#458

Merged
AfraHussaindeen merged 1 commit intowso2:masterfrom
AfraHussaindeen:master_sub-sub-deletefix
Apr 5, 2026
Merged

Add null check before removing sub-sub-attribute#458
AfraHussaindeen merged 1 commit intowso2:masterfrom
AfraHussaindeen:master_sub-sub-deletefix

Conversation

@AfraHussaindeen
Copy link
Copy Markdown
Contributor

@AfraHussaindeen AfraHussaindeen commented Apr 4, 2026

Purpose

  • $Subject

Summary by CodeRabbit

  • Bug Fixes
    • Fixed potential null reference error in sub-attribute deletion logic, improving application stability.

Comment on lines 137 to 141
Attribute parent = ((ComplexAttribute) grandParent).getSubAttribute(parentAttribute);
((ComplexAttribute) (parent)).removeSubAttribute(childAttribute);

if (parent != null) {
((ComplexAttribute) (parent)).removeSubAttribute(childAttribute);
}
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Log Improvement Suggestion No: 1

Suggested change
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);
}

Copy link
Copy Markdown

@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

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 4, 2026

Walkthrough

A null-check guard is added to the deleteSubSubAttribute(...) method in AbstractSCIMObject.java. The method now verifies that the parent sub-attribute exists before attempting to remove child attributes, preventing potential null pointer exceptions.

Changes

Cohort / File(s) Summary
Null-check Guard
modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java
Added conditional check to verify parent sub-attribute is non-null before invoking removeSubAttribute(childAttribute), preventing null pointer dereference in deleteSubSubAttribute(...).

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Poem

🐰 A null here, a null there,
Made deletion quite unfair,
But now we check before we strike—
The rabbit's guard works just right! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The PR description is largely incomplete, containing only a placeholder Purpose section with '$Subject' instead of actual content and missing all other required template sections. Complete the description by filling in all required sections including Goals, Approach, User Stories, Checklist items, Release Notes, Documentation, and other applicable sections from the template.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a null check before removing a sub-sub-attribute in the deleteSubSubAttribute method.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

Copy link
Copy Markdown

@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.

🧹 Nitpick comments (1)
modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java (1)

162-177: Consider applying similar null-check to deleteSubValuesSubAttribute.

For consistency and robustness, deleteSubValuesSubAttribute has the same potential NPE at line 168 where subAttributeList.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

📥 Commits

Reviewing files that changed from the base of the PR and between 76d21a5 and dc9900c.

📒 Files selected for processing (1)
  • modules/charon-core/src/main/java/org/wso2/charon3/core/objects/AbstractSCIMObject.java

@codecov
Copy link
Copy Markdown

codecov bot commented Apr 4, 2026

Codecov Report

❌ Patch coverage is 0% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 31.93%. Comparing base (297790b) to head (dc9900c).
⚠️ Report is 5 commits behind head on master.

Files with missing lines Patch % Lines
.../wso2/charon3/core/objects/AbstractSCIMObject.java 0.00% 2 Missing ⚠️

❌ 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              
Flag Coverage Δ
unit 31.05% <0.00%> (-0.01%) ⬇️

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.

@AfraHussaindeen AfraHussaindeen merged commit 2a6e4f7 into wso2:master Apr 5, 2026
4 of 5 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