Skip to content

feat: fix race condition in enforce() causing ArrayIndexOutOfBoundsException#513

Merged
hsluoyz merged 4 commits intomasterfrom
copilot/fix-arrayindexoutofboundsexception
Feb 12, 2026
Merged

feat: fix race condition in enforce() causing ArrayIndexOutOfBoundsException#513
hsluoyz merged 4 commits intomasterfrom
copilot/fix-arrayindexoutofboundsexception

Conversation

Copy link
Contributor

Copilot AI commented Feb 12, 2026

fix: #511

Race condition in CoreEnforcer.enforce() when policy list is modified during enforcement. Arrays sized with captured policyLen, but loop condition re-reads policy.size(), causing index overflow in concurrent scenarios.

Changes

  • CoreEnforcer.java:626: Use captured policyLen in loop condition instead of policy.size()
  • ConcurrentEnforcerTest.java: Add regression test exercising concurrent policy modifications during enforcement
// Before
final int policyLen = policy.size();  // Size at time T1
policyEffects = new Effect[policyLen];
matcherResults = new float[policyLen];
for (int i = 0; i < policy.size(); i++) {  // Size at time T2 - may differ
    policyEffects[i] = ...  // ArrayIndexOutOfBoundsException if T2 > T1
}

// After
final int policyLen = policy.size();
policyEffects = new Effect[policyLen];
matcherResults = new float[policyLen];
for (int i = 0; i < policyLen; i++) {  // Consistent with array sizing
    policyEffects[i] = ...
}

@CLAassistant
Copy link

CLAassistant commented Feb 12, 2026

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our Contributor License Agreement before we can accept your contribution.
1 out of 2 committers have signed the CLA.

✅ hsluoyz
❌ Copilot
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits February 12, 2026 14:40
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix ArrayIndexOutOfBoundsException in enforce() method Fix race condition in enforce() causing ArrayIndexOutOfBoundsException Feb 12, 2026
Copilot AI requested a review from hsluoyz February 12, 2026 14:45
@hsluoyz hsluoyz marked this pull request as ready for review February 12, 2026 14:52
@hsluoyz hsluoyz changed the title Fix race condition in enforce() causing ArrayIndexOutOfBoundsException feat: fix race condition in enforce() causing ArrayIndexOutOfBoundsException Feb 12, 2026
@hsluoyz hsluoyz merged commit cf3d8ac into master Feb 12, 2026
1 of 3 checks passed
@codecov-commenter
Copy link

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.98%. Comparing base (c617f4d) to head (7297e4b).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master     #513   +/-   ##
=======================================
  Coverage   67.98%   67.98%           
=======================================
  Files          63       63           
  Lines        3089     3089           
  Branches      574      574           
=======================================
  Hits         2100     2100           
  Misses        805      805           
  Partials      184      184           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

ArrayIndexOutOfBoundsException in enforce()

4 participants