pjfanning opened a new pull request, #1245:
URL: https://github.com/apache/poi/pull/1245
### The bug
`BaseXSSFEvaluationWorkbook.resolveBookIndex` strips the `[]` wrapper from a
book name with `substring(1, length()-2)`, which drops the trailing `]`, the
leading `[`, **and** the last character of the name itself:
```java
if (bookName.startsWith("[") && bookName.endsWith("]")) {
bookName = bookName.substring(1, bookName.length()-2); //
"[Book1.xlsx]" -> "Book1.xls"
}
```
The external-links lookup then misses, and unless the truncated name happens
to look like a `'file:///…'` reference the call ends in `IllegalStateException:
Book not linked for filename …`.
`FormulaParser.getBookName()` already strips the brackets, so the normal
parser path masks this. The branch is reached when a caller hands
`get3DReferencePtg` / `getNameXPtg` a `SheetIdentifier` whose book name still
has its brackets — which is what the "if still present" comment is there for.
### Also in the same method
* The absolute-file-reference check only matched `'file:///…'` **with** the
surrounding single quotes, working only because `getBookName()` happens to
leave them in place. It now accepts the reference with or without them.
* `findExternalLinkIndex` iterated the list from
`XSSFWorkbook.getExternalLinksTables()` without a null check, even though
`getExternalLinksTable(int)` and `addExternalLinksTable` both treat null as
possible. It now returns `-1` for a null list, and the placeholder-added case
re-fetches the list instead of assuming the one looked up earlier is the live
one.
### Tests
Three cases added to `TestXSSFEvaluationWorkbook`, each verified to fail
without the corresponding change:
* `testResolveBookIndexWithBracketedName` — uses the existing
`ref-56737.xlsx` sample (linked file name `56737.xlsx`); without the fix it
fails with `Book not linked for filename 56737.xls`.
* `testResolveBookIndexForUnquotedFileReference` — without the fix,
`file:///C:/temp/Book1.xlsx` is rejected.
* `testResolveBookIndexForQuotedFileReference` — covers the pre-existing
quoted form, including that a repeat lookup finds the placeholder rather than
adding a second one.
536 tests across `TestFormulaEvaluatorOnXSSF`, `TestXSSFFormulaEvaluation`,
`TestXSSFFormulaParser`, `TestExternalLinksTable` and the rest of the XSSF
formula suites pass.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]