Skip to content

Fix create word crash between articles - #567

Closed
valerybokov wants to merge 2 commits into
apache:trunkfrom
valerybokov:fix-createWord-crash-between-articles
Closed

valerybokov wants to merge 2 commits into
apache:trunkfrom
valerybokov:fix-createWord-crash-between-articles

Conversation

@valerybokov

Copy link
Copy Markdown

Problem

PDFTextStripper.getText() throws an IndexOutOfBoundsException with default settings when a page has
article beads and a new article starts on the same baseline as the previous one, e.g. two beads side by side:

java.lang.IndexOutOfBoundsException: Index 0 out of bounds for length 0
    at java.util.ArrayList.get(ArrayList.java:428)
    at org.apache.pdfbox.text.PDFTextStripper.createWord(PDFTextStripper.java:2043)

Cause

lastPosition in writePage() carries over from one article to the next, but the line buffer is new for
each article. When the first glyph of the next article overlaps the last line of the previous one and is far
enough to the right, a word separator is added to the still-empty line. normalizeAdd() then calls
createWord("", []), and since PDFBOX-6281 (f4dbe77) createWord() calls wordPositions.get(0)
unconditionally.

Fix

createWord() checks isFromActualText() only when wordPositions isn't empty. An empty word is
normalized as before, so the output matches the behavior before PDFBOX-6281: LEFT RIGHT, not an exception
(and not LEFTRIGHT). The requireNonNull check is removed: it could never report its message, because
get(0) throws first.

Test

TestTextStripper#testArticlesOnSameLine builds a page with two thread beads side by side, one word in each,
and expects "LEFT RIGHT\n". It fails with the exception above without the fix.
TestTextStripper, BidiTest and PDFTextStripperByAreaTest pass.


Per https://www.apache.org/legal/generative-tooling.html: portions of this PR were
produced with assistance from Claude Code (Anthropic), based on a bug was described in Apache PDFBOX Issue Tracker.

I've reviewed the generated code and confirm to the best of my knowledge that the output does not include any
third-party copyrighted material and is compatible with the Apache License 2.0.

valerybokov and others added 2 commits November 14, 2026 21:49
…rticle starts on the same line as the previous one

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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