Skip to content

Fix 11 issues in Okta Java SDK#1668

Merged
prachi-okta merged 3 commits intomasterfrom
sdk-bug-fixes
Jan 21, 2026
Merged

Fix 11 issues in Okta Java SDK#1668
prachi-okta merged 3 commits intomasterfrom
sdk-bug-fixes

Conversation

@prachi-okta
Copy link
Copy Markdown
Contributor

@prachi-okta prachi-okta commented Jan 15, 2026

All fixes verified and tested. Resource-specific caching demonstrated with User cache (5s TTL) showing 0ms cache hits vs 500ms API calls.

Here's a comprehensive explanation of the caching changes:

Caching System Improvements

Problem Statement

The SDK's cache invalidation logic had several critical issues causing stale cache entries after mutating operations (DELETE/PUT/POST), leading to integration test failures where deleted resources were still being returned from cache instead of throwing 404 errors.

Root Causes Identified

  1. Cross-Cache Invalidation Gap: Lifecycle operations (e.g., /users/{id}/lifecycle/suspend) used the default cache, but subsequent GET operations used resource-specific caches (e.g., User cache), causing stale data.

  2. Nested Resource Path Mismatch:

    • FederatedClaim endpoints use /federated-claims/ not /claims/
    • GroupPushMapping endpoints use /group-push/mappings/ not /push-mappings/
    • Path patterns weren't matching actual API paths
  3. Multiple Model Types: Some resources have multiple model classes (e.g., FederatedClaim and FederatedClaimRequestBody). DELETE invalidated one, but GET used the other, leaving stale cache.

  4. Single-Cache Strategy: Original logic invalidated only ONE cache per operation, but nested resources like /apps/{id}/sso/claims/{id} should invalidate from BOTH Application AND FederatedClaim caches.

Solution Implemented

1. Multi-Cache Invalidation Strategy

// Changed from single cache to ArrayList of ALL matching caches
java.util.List<String> resourceCacheNames = new java.util.ArrayList<>();

if (path.contains("/federated-claims/") || path.contains("/claims/")) {
    resourceCacheNames.add("com.okta.sdk.resource.model.FederatedClaim");
    resourceCacheNames.add("com.okta.sdk.resource.model.FederatedClaimRequestBody");
}
if (path.contains("/apps/")) {
    resourceCacheNames.add("com.okta.sdk.resource.model.Application");
}
// Loop through ALL and invalidate from each

2. Correct Path Pattern Matching

  • Fixed /federated-claims/ detection (not just /claims/)
  • Fixed /group-push/mappings/ detection (not just /push-mappings/)

3. Comprehensive Invalidation on Mutating Operations

  • Invalidate from current cache (based on returnType)
  • Invalidate from default cache (if different)
  • Invalidate from ALL resource-specific caches that match the path
  • Invalidate parent resource caches for sub-resource operations

4. Defensive Exception Handling

try {
    // Cache invalidation logic
} catch (Exception cacheEx) {
    // Don't let cache errors interfere with API exceptions
}

This ensures cache errors never mask legitimate API errors (like 404s).

Impact

  • Before: 151 integration test failures due to stale cache
  • After: 0 failures, all 431 tests passing (100% pass rate)
  • Test Coverage: Verified with ApplicationSSOFederatedClaimIT and GroupPushMappingIT

Technical Details

Issue(s)

Description

Category

  • Bugfix
  • Enhancement
  • New Feature
  • Library Upgrade
  • Configuration Change
  • Versioning Change
  • Unit or Integration Test(s)
  • Documentation

Signoff

  • I have submitted a CLA for this PR
  • Each commit message explains what the commit does
  • I have updated documentation to explain what my PR does
  • My code is covered by tests if required
  • I did not edit any automatically generated files

- Fix #1615/#1667: Change LinksResend.resend to array type (List<HrefObject>)
- Fix #1618: Add type validation for cached objects to prevent ClassCastException
- Fix #1619: Set default name for OIDCApplicationBuilder to OIDC_CLIENT
- Fix #1622: Correct expirePasswordWithTempPassword return type to TempPassword
- Fix #1642: Enable custom attributes for GroupProfile (OktaUserGroupProfile)
- Fix #1666: Change JUnit dependency scope from compile to test
- Fix #1657: Upgrade httpclient5 to 5.5.1 to fix connection pool leak
- Fix #1653: Add missing rootSessionId field to LogAuthenticationContext
- Fix #1650: Enable super.equals() call in PasswordPolicyRule for proper parent comparison
- Fix #1600: Implement resource-specific cache lookup in ApiClient
- Update SDK version to 25.0.1-SNAPSHOT

All fixes verified and tested. Resource-specific caching demonstrated with
User cache (5s TTL) showing 0ms cache hits vs 500ms API calls.
…1600)

- Fixed cache invalidation for DELETE operations on nested resources
- Added support for FederatedClaimRequestBody cache invalidation
- Fixed path matching for /federated-claims/ and /group-push/mappings/
- Implemented multi-cache invalidation to remove from all matching caches
- Added defensive exception handling to prevent cache errors from interfering with API operations

Resolves:
- #1618: Cache ClassCastException with type validation
- #1600: Resource-specific cache configuration

All integration tests passing (431 tests, 0 failures)
Copy link
Copy Markdown

@aniket-okta aniket-okta left a comment

Choose a reason for hiding this comment

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

LGTM 🚀

@prachi-okta prachi-okta merged commit 547f0ff into master Jan 21, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment