← Back to Pull requests

fix: preserve hyperlink ranges and register comments on their anchor cells #1340

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 14, 2026 11:28 UTC
Author

<!--
Thanks very much for contributing to Apache Fesod (Incubating)! Please make sure that your code changes
are covered with tests. And in case of new features or big changes
remember to adjust the documentation.

Feel free to ping committers for the review!

In case of an existing issue, reference it using one of the following:

Closed: #ISSUE
Related: #ISSUE

-->

Purpose of the pull request

Fix the two remaining downstream paths of #1332: hyperlinks with an explicit range, and comments with an explicit anchor. Both lose the requested position after Fesod hands it to POI. POI rewrites the hyperlink range inside setHyperlink, and setCellComment registers the comment on the data cell instead of the anchor cell.

Related: #1332
Related: #1333
Related: #1341

Why these two changes are in one PR

I originally split them into #1340 and #1341 to keep one PR to one problem. That split turns out to be worse here. Both paths depend on the same shared helper change in #1333, where StyleUtil.getCellCoordinate starts accepting an absolute index of 0. Once that change is in main, a comment anchored at A1 while writing B2 is checked against A1 by POI, while the registered reference does not necessarily follow it. Landing only the hyperlink fix would leave main in a half-fixed state, with comment ownership still inconsistent between streaming and in-memory writes.

These two changes are two halves of one fix for #1332, not two unrelated problems. Keeping them in one PR lets the maintainers review and land the complete change together. #1341 has been closed in favour of this PR. Please keep #1332 open until this PR lands.

What's changed?

Hyperlink range

fillHyperLink used to hand the range to POI before attaching it:

hyperlink.setFirstRow(...);
hyperlink.setFirstColumn(...);
hyperlink.setLastRow(...);
hyperlink.setLastColumn(...);
cell.setHyperlink(hyperlink);

setHyperlink then replaced the reference with the cell it was called on, so a HyperlinkData covering A1:C3 collapsed onto its own cell and the requested corners were lost. The four values are now computed first and applied after setHyperlink. Nothing else in the method changes.

Comment ownership

fillComment ended with cell.setCellComment(comment), which attaches the comment to the cell that carries the data. POI uses the anchor and the stored reference for two different things:

  • CommentsTable.createNewComment looks a comment up by the top left corner of its anchor

  • XSSFCell.setCellComment stores the reference of the cell it is called on
  • So a comment anchored at A1 while writing B2 was drawn at A1 but stored under B2. The reference is now taken from the anchor:

    comment.setAddress(anchor.getRow1(), anchor.getCol1());
    

    Comment.setAddress exists on both XSSFComment and HSSFComment, so the streaming and the in-memory writer go through the same line. Nothing else in the method changes. Two comments anchored at the same cell are still rejected with the same Multiple cell comments message. That rejection is intentional, and the point of this change is that the rejection now matches where the comment is drawn.

    Why this needs #1333

    Both halves need StyleUtil.getCellCoordinate to accept an absolute index of 0. Before that change, absolute 0 was ignored and an A1 range or anchor silently fell back to the data cell. #1333 owns that helper change. Neither of the two commits owned by this PR modifies it; the StyleUtil change comes from #1333 and will disappear once this branch is rebased.

    About the commit list

    This branch is still stacked on the head of #1333, so the commit list also shows c34893a7 and the merge commit 45b16dab from that PR. The first is the author's commit from #1333, the second was created when a maintainer updated that branch with main; both are carried here only so the two fixes can be exercised on top of them.

    The two commits that belong to this PR are 87f72468 (hyperlink range) and 12827e21 (comment ownership, folded in from #1341). Once #1333 lands I will rebase onto main and force-push, after which the diff contains only those two commits.

    Scope

    Two production methods in AbstractExcelWriteExecutor, fillHyperLink and fillComment, plus two new test classes. The shared helper from #1333 is left untouched.

    Tests

    HyperlinkRangeWriteTest runs every case on both XLSX and XLS: an explicit range A1:C3, no coordinates, a range away from the origin C2:E4, relative offsets, a negative absolute index, and two links with different ranges in one sheet. 12 cases, green on JDK 8 and JDK 21.

    CommentAnchorOwnershipTest runs every case on both XLSX and XLS: no coordinate, an absolute anchor, relative offsets, a negative absolute index, two comments with different anchors, the anchor and the owner agreeing, and the duplicate case in both the in-memory and the streaming writer. 16 cases, green on JDK 8 and JDK 21.

    Both test classes were run before the two fixes were combined, with spotless:check and checkstyle:check passing at that point. I will rerun them on the combined branch and report the result here.

    Checklist

  • I have read the Contributor Guide.

  • I have written the necessary doc or comment.

  • I have added the necessary unit tests and all cases have passed.
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: skytin1004 Review duration: 23364m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #1340"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 27.7% · Safe to merge
    27.7%
    Repository