Skip to content

Fix off-by-one error in createTempFileSecure - #237

Draft
cursor[bot] wants to merge 1 commit into
mainfrom
arrayindexoutofboundsexception-length3-index3-zptgtm
Draft

Fix off-by-one error in createTempFileSecure#237
cursor[bot] wants to merge 1 commit into
mainfrom
arrayindexoutofboundsexception-length3-index3-zptgtm

Conversation

@cursor

@cursor cursor Bot commented Jul 9, 2026

Copy link
Copy Markdown

Summary

Fixed an off-by-one error in MyBaseActivity.createTempFileSecure that was causing ArrayIndexOutOfBoundsException when accessing array elements.

Changes

  • Changed the condition from index > cacheFiles.length to index >= cacheFiles.length on line 163
  • This prevents the loop from allowing index to equal the array length, which would be out of bounds

Root Cause

The rejection condition in the while loop used index > cacheFiles.length instead of >=, allowing the index to reach a value equal to the array length. When cacheFiles[index] was accessed on line 171 with index == cacheFiles.length (e.g., 3 for a length-3 array), it threw ArrayIndexOutOfBoundsException: length=3; index=3.

Testing

This fix ensures that only valid array indices (0 to length-1) are used when accessing cacheFiles[index], preventing the crash when adding attachments in EmpowerPlantActivity.

Fixes ANDROID-JG

Open in Web Open in Cursor 

Changed index > cacheFiles.length to index >= cacheFiles.length
to prevent ArrayIndexOutOfBoundsException when index equals array length.

Fixes [ANDROID-JG](https://demo.sentry.io/issues/7601217253/)
@sentry

sentry Bot commented Jul 9, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App Name App ID Version Configuration
Android com.example.vu.android 24.12.26 (241226) release
Android com.example.vu.android 24.12.26 (241226) debug
Android com.example.vu.android 24.12.26 (241226) release

⚙️ android Build Distribution Settings

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 0% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 0.00%. Comparing base (fbd7a20) to head (1e5b2e9).

Files with missing lines Patch % Lines
...in/java/com/example/vu/android/MyBaseActivity.java 0.00% 1 Missing ⚠️
Additional details and impacted files
@@          Coverage Diff          @@
##            main    #237   +/-   ##
=====================================
  Coverage   0.00%   0.00%           
=====================================
  Files         16      16           
  Lines        875     875           
  Branches      65      65           
=====================================
  Misses       875     875           

☔ View full report in Codecov by Harness.
📢 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.

1 participant