Skip to content

Comments

fix: reduce thread blocking by double null check in invokeMethod()#523

Merged
lukaszlenart merged 1 commit intoognl-3-4-xfrom
fix/reduce-thread-blocking-double-null-check
Dec 29, 2025
Merged

fix: reduce thread blocking by double null check in invokeMethod()#523
lukaszlenart merged 1 commit intoognl-3-4-xfrom
fix/reduce-thread-blocking-double-null-check

Conversation

@lukaszlenart
Copy link
Collaborator

Summary

Cherry-pick of PR #521 adapted for Java 8 compatibility.

  • Implements double-null-check pattern for _methodAccessCache and _methodPermCache
  • Avoids synchronizing on Method objects when cache values already exist
  • Reduces thread contention in high-concurrency scenarios

Problem

Production environments experienced severe thread blocking (980+ threads blocked) waiting to acquire locks on java.lang.reflect.Method objects in OgnlRuntime.invokeMethod(). The root cause was that all threads competed for the same Method monitor even when cache values already existed.

Solution

Move cache check outside the synchronized block (first null check), then re-check inside if null (double null check). This eliminates unnecessary synchronization when the cache is already populated.

Key Adaptations for Java 8

  • Kept method.isAccessible() instead of Java 9+ method.canAccess()
  • Preserved full securityManager logic for _methodPermCache
  • No var usage (explicit types only)

Test plan

  • All 993 tests pass (./mvnw clean test)
  • Verified Java 8 compatibility

🤖 Generated with Claude Code

Cherry-pick of PR #521 adapted for Java 8 compatibility.
Implements double-null-check pattern for _methodAccessCache and
_methodPermCache to avoid synchronizing on Method objects when
cache values already exist.

Fixes thread contention issues where multiple threads would block
waiting to acquire locks on java.lang.reflect.Method objects even
when cache values were already present.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
C Maintainability Rating on New Code (required ≥ A)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@lukaszlenart lukaszlenart merged commit a8b744e into ognl-3-4-x Dec 29, 2025
4 of 5 checks passed
@lukaszlenart lukaszlenart deleted the fix/reduce-thread-blocking-double-null-check branch December 29, 2025 09:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant