CAMEL-20199: Replace synchronized with ReentrantLock in OAuth and security components - #25246
Conversation
…urity components Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 11 tested, 29 compile-only — current: 11 all testedMaveniverse Scalpel detected 40 affected modules (current approach: 11).
|
gnodet
left a comment
There was a problem hiding this comment.
Looks good ✅
Clean, correct mechanical conversion of synchronized blocks/methods to ReentrantLock across four OAuth and security component files, following the standard lock-try-finally-unlock pattern established in CAMEL-20199. No semantic changes, no regressions, CI green.
Key observations:
- All four conversions correctly preserve the original synchronization scope. Instance-level
synchronizedmethods become instance-level ReentrantLock fields. Per-keysynchronized(lock)blocks usingConcurrentMap<String, Object>correctly change the map value type toReentrantLock. - No external code synchronizes on the
thismonitor ofKeycloakPublicKeyResolverorKeyRotationScheduler, so the switch from intrinsic monitors to explicit locks has no observable impact on callers. - The
clear()/clearDiscoveryCache()methods that wipe the lock maps still work identically — a thread holding a removed lock completes normally; new requests create fresh locks.
Pre-existing note (not a regression): KeycloakPublicKeyResolver.clearCache() modifies keyCache and lastRefreshTime without holding the lock, which could race with a concurrent refreshKeys(). This was never synchronized before this PR either.
This review was generated by an AI agent and may contain inaccuracies. Please verify all suggestions before applying.
Claude Code on behalf of Guillaume Nodet
Summary
Claude Code on behalf of gnodet
Part of CAMEL-20199 (migrate from
synchronizedto explicit lock constructs).This PR replaces
synchronizedblocks and methods withReentrantLockin four OAuth and security component files:KeycloakPublicKeyResolver(camel-keycloak):refreshKeys()converted fromsynchronizedmethod toReentrantLockDefaultOAuthTokenValidationFactory(camel-oauth): Discovery lock map changed fromConcurrentMap<String, Object>withsynchronized(lock)toConcurrentMap<String, ReentrantLock>with explicit lock/unlockJwksCache(camel-oauth): BothrefreshJwkSet()andfetchAndCache()converted fromsynchronizedblocks toReentrantLockKeyRotationScheduler(camel-pqc):checkAndRotate()converted fromsynchronizedmethod toReentrantLockAll conversions follow the standard
lock.lock(); try { ... } finally { lock.unlock(); }pattern.Test plan
camel-oauthtests pass (119 tests, 0 failures)camel-keycloaktests pass (122 tests, 0 failures)camel-pqctests pass (210 tests, 0 failures)🤖 Generated with Claude Code