Skip to content

Conversation

@lposen
Copy link
Contributor

@lposen lposen commented Nov 19, 2025

🔹 JIRA Ticket(s) if any

✏️ Description

In Android, fix retryInteraval so that it will update correctly on re-initialization.

Testing

  1. cd into example
  2. In Terminal 1, run:
    bash watchman watch-del-all yarn start --reset-cache
  3. In terminal 2, run:
    bash yarn android
  4. In useIterableApp.tsx, uncomment line 210 ( return 'InvalidToken')
  5. Open the console by pressing j in the terminal in which you ran yarn start
  6. Click "Login" in the app.
  7. In the console, you should see "authHandler" being logged around every 5 seconds.
  8. In useIterableApp.tsx find where retryInterval is set (~line 154). Update it to 2.
  9. Refresh the app by pressing r in the terminal in which you ran yarn start
  10. Click "Login" in the app.
  11. In the console, you should see "authHandler" being logged around every 2 seconds.

@github-actions
Copy link

github-actions bot commented Nov 19, 2025

Lines Statements Branches Functions
Coverage: 58%
58.36% (328/562) 33.03% (75/227) 56.58% (116/205)

@qltysh
Copy link

qltysh bot commented Nov 19, 2025

Diff Coverage: Not applicable. There was no coverage data reported for the files in this diff.

Total Coverage: This PR will not change total coverage.

🛟 Help
  • Diff Coverage: Coverage for added or modified lines of code (excludes deleted files). Learn more.

  • Total Coverage: Coverage for the whole repository, calculated as the sum of all File Coverage. Learn more.

  • File Coverage: Covered Lines divided by Covered Lines plus Missed Lines. (Excludes non-executable lines including blank lines and comments.)

    • Indirect Changes: Changes to File Coverage for files that were not modified in this PR. Learn more.

This is from Qlty Cloud, the successor to Code Climate Quality. Learn more.

@qltysh
Copy link

qltysh bot commented Nov 21, 2025

4 new issues

Tool Category Rule Count
qlty Duplication Found 22 lines of identical code in 2 locations (mass = 151) 2
qlty Structure High total complexity (count = 57) 1
qlty Structure Function with many returns (count = 10): IterableAppProvider 1

This is from Qlty Cloud, the successor to Code Climate Quality. Learn more.

@lposen lposen changed the title [SDK-196] convert retry interval from seconds to milliseconds in RetryPolicy configuration [SDK-196] Fix retryInterval not being able to be updated Nov 21, 2025
@lposen lposen requested a review from Copilot November 21, 2025 01:28
@lposen lposen marked this pull request as ready for review November 21, 2025 01:29
Copilot finished reviewing on behalf of lposen November 21, 2025 01:31
Copy link
Contributor

Copilot AI left a 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 aims to fix an issue where the retryInterval configuration was not being properly updated on Android. The fix introduces a reflection-based workaround to update the retry policy on existing authManager instances after re-initialization. However, the PR description mentions converting seconds to milliseconds, which is not evident in the actual code changes.

Key Changes:

  • Added reflection code to access and update package-private authRetryPolicy field in IterableAuthManager
  • Updated example app to test retry behavior with logging and adjusted initialization flow
  • Updated CHANGELOG to document the fix

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.

File Description
android/src/main/java/com/iterable/reactnative/RNIterableAPIModuleImpl.java Added reflection-based workaround to update retry policy on existing authManager in both initialization methods
example/src/hooks/useIterableApp.tsx Modified example app to test retry behavior: added timestamp tracking in authHandler, changed retryInterval value, and updated initialization flow
CHANGELOG.md Added entry for version 2.2.0-alpha.2 documenting the retryInterval fix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +162 to +183
try {
// Use reflection to access package-private fields and methods
java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy");
configRetryPolicyField.setAccessible(true);
Object retryPolicy = configRetryPolicyField.get(config);

if (retryPolicy != null) {
java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager");
getAuthManagerMethod.setAccessible(true);
IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance());

if (authManager != null) {
// Update the retry policy field on the authManager
java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy");
authRetryPolicyField.setAccessible(true);
authRetryPolicyField.set(authManager, retryPolicy);
IterableLogger.d(TAG, "Updated retry policy on existing authManager");
}
}
} catch (Exception e) {
IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage());
}
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The code in this method (lines 162-183) is an exact duplicate of the reflection logic in initializeWithApiKey (lines 99-120). This violates the DRY (Don't Repeat Yourself) principle and makes maintenance harder.

Consider extracting this logic into a private helper method that can be called from both initialization methods:

private void updateAuthManagerRetryPolicy(IterableConfig config) {
    // Move the try-catch block here
}

Copilot uses AI. Check for mistakes.
config.retryPolicy = {
maxRetry: 5,
retryInterval: 10,
retryInterval:5,
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Missing space after colon. Should be retryInterval: 5 for consistency with the code style.

Suggested change
retryInterval:5,
retryInterval: 5,

Copilot uses AI. Check for mistakes.
across application

### Fixes
* Fixed Android `retryInterval` not being updated on re-initialization.
Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

The changelog entry states that retryInterval is "not being updated on re-initialization," but based on the PR description, the actual fix is about converting seconds to milliseconds. However, this conversion is missing from the code changes in Serialization.java. The changelog should more accurately describe what was actually fixed (the workaround to update retry policy on existing authManager).

Suggested change
* Fixed Android `retryInterval` not being updated on re-initialization.
* Fixed Android `retryInterval` value to be correctly converted from seconds to milliseconds and added workaround to update retry policy on existing authManager.

Copilot uses AI. Check for mistakes.
Comment on lines +95 to +121
// Update retry policy on existing authManager if it was already created
// This fixes the issue where retryInterval is not respected after
// re-initialization
// TODO [SDK-197]: Fix the root cause of this issue, instead of this hack
try {
// Use reflection to access package-private fields and methods
java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy");
configRetryPolicyField.setAccessible(true);
Object retryPolicy = configRetryPolicyField.get(config);

if (retryPolicy != null) {
java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager");
getAuthManagerMethod.setAccessible(true);
IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance());

if (authManager != null) {
// Update the retry policy field on the authManager
java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy");
authRetryPolicyField.setAccessible(true);
authRetryPolicyField.set(authManager, retryPolicy);
IterableLogger.d(TAG, "Updated retry policy on existing authManager");
}
}
} catch (Exception e) {
IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage());
}

Copy link

Copilot AI Nov 21, 2025

Choose a reason for hiding this comment

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

Using reflection to access package-private fields and methods is fragile and will break if the internal structure of the Iterable SDK changes. This approach:

  1. Bypasses encapsulation, accessing private implementation details
  2. May fail silently if field/method names change in SDK updates
  3. Could cause runtime exceptions in different SDK versions
  4. Makes the code difficult to maintain and test

Consider working with the Iterable SDK team to expose a proper API for updating the retry policy after initialization, or alternatively, track the issue [SDK-197] mentioned in the TODO to fix the root cause.

Suggested change
// Update retry policy on existing authManager if it was already created
// This fixes the issue where retryInterval is not respected after
// re-initialization
// TODO [SDK-197]: Fix the root cause of this issue, instead of this hack
try {
// Use reflection to access package-private fields and methods
java.lang.reflect.Field configRetryPolicyField = config.getClass().getDeclaredField("retryPolicy");
configRetryPolicyField.setAccessible(true);
Object retryPolicy = configRetryPolicyField.get(config);
if (retryPolicy != null) {
java.lang.reflect.Method getAuthManagerMethod = IterableApi.getInstance().getClass().getDeclaredMethod("getAuthManager");
getAuthManagerMethod.setAccessible(true);
IterableAuthManager authManager = (IterableAuthManager) getAuthManagerMethod.invoke(IterableApi.getInstance());
if (authManager != null) {
// Update the retry policy field on the authManager
java.lang.reflect.Field authRetryPolicyField = authManager.getClass().getDeclaredField("authRetryPolicy");
authRetryPolicyField.setAccessible(true);
authRetryPolicyField.set(authManager, retryPolicy);
IterableLogger.d(TAG, "Updated retry policy on existing authManager");
}
}
} catch (Exception e) {
IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage());
}
// NOTE: Unable to update retry policy on existing authManager after initialization
// until SDK-197 is resolved. Reflection-based hack removed for safety and maintainability.
// If retryInterval is not respected after re-initialization, this is a known limitation.

Copilot uses AI. Check for mistakes.
@lposen lposen requested a review from Ayyanchira November 21, 2025 01:40
@lposen lposen added the jwt label Nov 21, 2025
}
}
} catch (Exception e) {
IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage());
Copy link

Choose a reason for hiding this comment

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

Found 22 lines of identical code in 2 locations (mass = 151) [qlty:identical-code]

}
}
} catch (Exception e) {
IterableLogger.e(TAG, "Failed to update retry policy: " + e.getMessage());
Copy link

Choose a reason for hiding this comment

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

Found 22 lines of identical code in 2 locations (mass = 151) [qlty:identical-code]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants