Conversation
|
CodeAnt AI is reviewing your PR. Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
📝 WalkthroughWalkthroughTwo extension files were refactored to improve null-safety handling by introducing local variable caching and graceful defaults instead of direct map access or non-null assertions. A new comprehensive test file was added to verify robust null handling across deserialization helpers. Changes
Estimated Code Review Effort🎯 2 (Simple) | ⏱️ ~15 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
📝 Coding Plan
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 |
Review Summary by QodoAdd nullability checks and comprehensive test coverage
WalkthroughsDescription• Replace unsafe non-null assertions with safe nullability checks - buttonSettingsFromMap: Use safe call with default ButtonType.MORE - deserializeUserDecision: Extract serviceId with null-coalescing operator • Add comprehensive test suite for nullability handling - Tests cover null entries in arrays and missing fields - Validates graceful handling of null values in deserialization Diagramflowchart LR
A["Unsafe Non-null Assertions"] -->|Replace with safe calls| B["Safe Nullability Checks"]
B -->|Validate with| C["NullabilityTest Suite"]
C -->|Ensures| D["Graceful Null Handling"]
File Changes1. android/src/main/java/com/usercentrics/reactnative/extensions/BannerSettingsExtensions.kt
|
Code Review by Qodo
1. Wrong default button type
|
Sequence DiagramThis PR hardens Android Kotlin extension parsing against null values coming from React Native 0.77 and later. It skips invalid user decision entries and applies a safe default button type when the map field is missing. sequenceDiagram
participant RN as React Native Layer
participant Ext as Kotlin Extensions
participant SDK as Usercentrics SDK
RN->>Ext: Send user decisions array
Ext->>Ext: Iterate entries
alt Map and serviceId present
Ext->>SDK: Create and collect UserDecision
else Null map or missing serviceId
Ext->>Ext: Skip entry
end
Ext-->>RN: Return filtered user decisions
RN->>Ext: Send button settings map
Ext->>Ext: Resolve button type or default MORE
Ext->>SDK: Build ButtonSettings
Ext-->>RN: Return safe button settings
Generated by CodeAnt AI |
|
PR Summary: Add null-safety checks to deserialization logic and add unit tests to prevent NPEs from null/missing RN map/array entries.
|
android/src/main/java/com/usercentrics/reactnative/extensions/BannerSettingsExtensions.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/extensions/UserDecisionExtensions.kt
Show resolved
Hide resolved
|
Reviewed up to commit:d9995ee4a8ca0e67d8095a2595344d1f44981762 |
android/src/main/java/com/usercentrics/reactnative/extensions/BannerSettingsExtensions.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/extensions/UserDecisionExtensions.kt
Show resolved
Hide resolved
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
android/src/test/java/com/usercentrics/reactnative/extensions/NullabilityTest.kt (1)
172-188: Add one test for missing/nullconsentwith validserviceId.Given this PR’s nullability focus, a targeted case here would lock expected behavior for that input shape and prevent regressions.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@android/src/test/java/com/usercentrics/reactnative/extensions/NullabilityTest.kt` around lines 172 - 188, Add a unit test in NullabilityTest.kt named something like `deserializeUserDecision_handlesMissingOrNullConsent_withValidServiceId` that constructs a JavaOnlyArray with entries where serviceId is present but consent is omitted and one where consent is explicitly null (plus a control entry with consent true), calls deserializeUserDecision(), and asserts that each entry with a valid serviceId is included in the result and that their consent values match the expected default behavior (e.g., false for missing/null consent) — reference deserializeUserDecision and assert on result[i].serviceId and result[i].consent to lock the behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In
`@android/src/main/java/com/usercentrics/reactnative/extensions/UserDecisionExtensions.kt`:
- Around line 17-20: deserializeUserDecision currently drops entries with null
serviceId silently; update it to signal when entries were skipped (e.g., return
a result object or pair containing the deserialized List<UserDecision> plus a
count/flag of skipped entries or throw a descriptive exception) and then change
the RNUsercentricsModule call sites that pass the result directly to the SDK
save methods (the functions that invoke the SDK save — locate usages around
where you call saveUserDecisions/saveDecisions) to check that signal: if any
entries were skipped, return an error/promise rejection to JS with a clear
message listing how many/which entries were dropped instead of calling the SDK,
otherwise proceed to call the SDK; ensure the unique symbol
deserializeUserDecision is updated and referenced by the RNUsercentricsModule
callers so JS consumers receive explicit feedback when invalid entries are
present.
---
Nitpick comments:
In
`@android/src/test/java/com/usercentrics/reactnative/extensions/NullabilityTest.kt`:
- Around line 172-188: Add a unit test in NullabilityTest.kt named something
like `deserializeUserDecision_handlesMissingOrNullConsent_withValidServiceId`
that constructs a JavaOnlyArray with entries where serviceId is present but
consent is omitted and one where consent is explicitly null (plus a control
entry with consent true), calls deserializeUserDecision(), and asserts that each
entry with a valid serviceId is included in the result and that their consent
values match the expected default behavior (e.g., false for missing/null
consent) — reference deserializeUserDecision and assert on result[i].serviceId
and result[i].consent to lock the behavior.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 616de5f8-c4b2-4f1c-885a-08207ff54258
📒 Files selected for processing (3)
android/src/main/java/com/usercentrics/reactnative/extensions/BannerSettingsExtensions.ktandroid/src/main/java/com/usercentrics/reactnative/extensions/UserDecisionExtensions.ktandroid/src/test/java/com/usercentrics/reactnative/extensions/NullabilityTest.kt
android/src/main/java/com/usercentrics/reactnative/extensions/UserDecisionExtensions.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/extensions/BannerSettingsExtensions.kt
Show resolved
Hide resolved
android/src/main/java/com/usercentrics/reactnative/extensions/UserDecisionExtensions.kt
Show resolved
Hide resolved
|
CodeAnt AI finished reviewing your PR. |
CI Feedback 🧐A test triggered by this PR failed. Here is an AI-generated analysis of the failure:
|
|
CodeAnt AI is running Incremental review Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
|
CodeAnt AI Incremental review completed. |
User description
Summary by CodeRabbit
Bug Fixes
Tests
CodeAnt-AI Description
Skip null entries and default missing banner button type to avoid crashes during JS-native parsing
What Changed
Impact
✅ Fewer Android crashes during settings parsing✅ Safer handling of null entries from React Native arrays✅ Consistent default banner button when button type is missing💡 Usage Guide
Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.
Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.
Example
Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
This helps CodeAnt AI learn and adapt to your team's coding style and standards.
Example
Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.