Skip to content

Fix IndexOutOfBoundsException in MetronomeInter when equalIndex is 0#894

Merged
hbitteur merged 1 commit intoAudiveris:developmentfrom
mgibson91:fix/metronome-inter-bounds-check
Mar 25, 2026
Merged

Fix IndexOutOfBoundsException in MetronomeInter when equalIndex is 0#894
hbitteur merged 1 commit intoAudiveris:developmentfrom
mgibson91:fix/metronome-inter-bounds-check

Conversation

@mgibson91
Copy link
Copy Markdown
Contributor

Summary

Fixes #812 — tempo text like "♩ = 100" causes IndexOutOfBoundsException: Index -1 during the TEXTS step when OCR places the note symbol in a separate word before the "=" sign.

Root cause: MetronomeInter.create() at line 942 does line.getWords().get(equalIndex - 1) without checking that equalIndex > 0. When "=" is the first word (equalIndex == 0), it tries get(-1).

Fix: One-line bounds check:

// Before:
if (ctx.charIndex == -1) {
// After:
if (ctx.charIndex == -1 && equalIndex > 0) {

The existing handler at line 948 (reporter.alert("Note characters not found...")) already covers the "not found" case — it raises ParsingException which is caught at line 985. No behavioral change for the normal case where equalIndex > 0.

Testing

Verified with a hymnal PDF (Amazing Grace) that previously required OCR-disabled fallback to complete:

  • Before patch: TEXTS step crashes → no MusicXML output
  • After patch: Completes on first attempt with OCR enabled, 141 <lyric> elements extracted correctly

When OCR reads a tempo marking where the note symbol is in a separate
word before "=" (e.g. "♩ = 100"), equalIndex can be 0. The code at
line 942 then tries get(equalIndex - 1) = get(-1), which throws
IndexOutOfBoundsException: Index -1.

Adding a bounds check (equalIndex > 0) lets execution fall through to
the existing reporter.alert() handler on line 948, which raises a
ParsingException caught at line 985.

Fixes Audiveris#812
@mgibson91 mgibson91 force-pushed the fix/metronome-inter-bounds-check branch from cc6de93 to 6105048 Compare February 21, 2026 22:45
@hbitteur
Copy link
Copy Markdown
Contributor

hbitteur commented Feb 22, 2026 via email

@hbitteur hbitteur merged commit bc974a1 into Audiveris:development Mar 25, 2026
@hbitteur
Copy link
Copy Markdown
Contributor

@mgibson91
I just merged your PR into the development branch.
Please forgive me for being so late, and thank you for your work.

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.

2 participants