-
Notifications
You must be signed in to change notification settings - Fork 0
[Review] Fix concurrent group access to prevent NullPointerException #10
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
base: feature-group-concurrency-update
Are you sure you want to change the base?
Conversation
Closes #40368 Signed-off-by: vramik <[email protected]>
AncD8972
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.
🤖 DiffCOT AI Code Review
The PR adds a null check in GroupAdapter.getSubGroupsCount() to prevent NPE during concurrent group access, adds an @OverRide annotation, removes unused code, and adds a concurrency test.
| Assessment | Score |
|---|---|
| 7/10 |
✅ Positive Aspects
- Good defensive programming by adding null check to prevent NPE in concurrent scenarios
- The test properly simulates concurrent access patterns that could trigger the original bug
- Clean removal of unused method in GroupUtils improves code maintainability
- Adding @OverRide annotation improves code clarity and enables compiler checking
💡 Suggestions for Improvement
- Consider adding @nullable annotation to getSubGroupsCount() if null return is intentional
- Consider making the concurrency test more robust by adding assertions about expected behavior
- Document why modelSupplier.get() can return null in this specific scenario
🔍 Issues Found: 3
- 🔴 High: 0
- 🟡 Medium: 2
- 🟢 Low: 1
See inline comments below for details.
Generated by DiffCOT AI Code Review
| GroupModel model = modelSupplier.get(); | ||
| return model == null ? null : model.getSubGroupsCount(); |
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.
🟡 MEDIUM | bug
Returning null from getSubGroupsCount() when model is null may cause NPE in callers that expect a Long value. This is a defensive fix but shifts the NPE risk to callers.
💡 Suggestion: Consider returning 0L instead of null, or document the null return value with @nullable annotation.
| GroupModel model = modelSupplier.get(); | |
| return model == null ? null : model.getSubGroupsCount(); | |
| GroupModel model = modelSupplier.get(); | |
| return model == null ? 0L : model.getSubGroupsCount(); |
|
|
||
|
|
||
| @Test | ||
| public void createMultiDeleteMultiReadMulti() { |
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.
🟢 LOW | typo
Variable name 'groupUuuids' has an extra 'u' - should be 'groupUuids'.
💡 Suggestion: Fix the typo in variable name.
| public void createMultiDeleteMultiReadMulti() { | |
| List<String> groupUuids = new ArrayList<>(); |
| } | ||
| } |
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.
🟡 MEDIUM | logic_defect
The test creates a thread but never joins it, which could cause the test to finish before the thread completes, making the test unreliable.
💡 Suggestion: Store the thread reference and join it after setting deletedAll to true.
| } | |
| } | |
| Thread readerThread = new Thread(() -> { | |
| while (!deletedAll.get()) { | |
| try { | |
| // just loading briefs | |
| managedRealm.admin().groups().groups(null, 0, Integer.MAX_VALUE, true); | |
| } catch (Exception e) { | |
| caughtExceptions.add(e); | |
| } | |
| } | |
| }); | |
| readerThread.start(); | |
| // delete groups | |
| groupUuuids.forEach(groupUuid -> { | |
| managedRealm.admin().groups().group(groupUuid).remove(); | |
| }); | |
| deletedAll.set(true); | |
| try { | |
| readerThread.join(5000); // Wait max 5 seconds for thread to finish | |
| } catch (InterruptedException e) { | |
| Thread.currentThread().interrupt(); | |
| } |
Mirrored from ai-code-review-evaluation#10.
Test 10