Bug 168008 - XTextRangeCompare doesn't throw when ranges are in different texts
Summary: XTextRangeCompare doesn't throw when ranges are in different texts
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
25.2.0.0 alpha0+
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:26.2.0 target:25.8.1 target:25...
Keywords: bibisected, bisected, regression
Depends on:
Blocks:
 
Reported: 2025-08-19 06:53 UTC by Adomas Venčkauskas
Modified: 2025-08-26 15:51 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Adomas Venčkauskas 2025-08-19 06:53:20 UTC
Description:
Per docs, XTextRangeCompare.compareRegionEnds(xR1, xR2) throws com::sun::star::lang::IllegalArgumentException	if either xR1 or xR2 is not within this text.

This is true in 24.8, but no longer true in 25.2. Zotero extension behaviour depends on this function throwing.


Steps to Reproduce:
Option Explicit

Sub InsertFootnoteAndCompare()
    Dim doc As Object, bodyText As Object, viewCurs As Object, bodyCurs As Object
    doc = ThisComponent
    bodyText = doc.Text
    viewCurs = doc.CurrentController.getViewCursor()

    ' 1) Insert a footnote at the current cursor
    Dim footnote As Object
    footnote = doc.createInstance("com.sun.star.text.Footnote")
    bodyText.insertTextContent(viewCurs, footnote, False)

    ' 2) Put some sample text into the footnote
    '    Footnote service exports XText, so we can get its text and write into it.
    Dim fText As Object, fCur As Object
    fText = footnote.getText()                 ' the text container inside the footnote
    fCur = fText.createTextCursor()
    fText.insertString(fCur, "This is the footnote text. Alpha beta gamma delta.", False)

    ' 3) Build a body range: from start of paragraph to current caret
    bodyCurs = bodyText.createTextCursorByRange(viewCurs)
    bodyCurs.gotoStartOfParagraph(False)
    bodyCurs.gotoRange(viewCurs, True)         ' select from start-of-paragraph to caret
    Dim bodyRange As Object
    bodyRange = bodyCurs

    ' 4) Compare two ranges in different Text objects
    Dim result As Integer
    result = fText.compareRegionStarts(bodyRange, fCur)
    MsgBox "Result " & result
End Sub

Actual Results:
A message box is shown with result

Expected Results:
An error is thrown


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 25.2.5.2 (X86_64) / LibreOffice Community
Build ID: 03d19516eb2e1dd5d4ccd751a0d6f35f35e08022
CPU threads: 16; OS: Linux 6.8; UI render: default; VCL: gtk3
Locale: lt-LT (en_US.UTF-8); UI: en-US
Calc: threaded
Comment 1 Saburo 2025-08-23 03:09:12 UTC
reproducible
Version: 26.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 953a4159ba48b2901e6b1660fc89960fcaa87b0c
CPU threads: 4; OS: Linux 6.16; UI render: default; VCL: gtk3
Locale: ja-JP (ja_JP.UTF-8); UI: en-US
Calc: threaded

first bad commit
Version: 25.2.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: 27e9fd67260b8ad321cf0f8722e2db8a08473927
CPU threads: 4; OS: Linux 6.16; UI render: default; VCL: gtk3
Locale: ja-JP (ja_JP.UTF-8); UI: en-US
Calc: threaded

commit 27e9fd67260b8ad321cf0f8722e2db8a08473927
author	Noel Grandin <noel.grandin@collabora.co.uk>	Thu Jun 13 09:01:50 2024 +0200

tdf#144208 speedup doc with lots of redline (7)

reduce dynamic_cast cost

Change-Id: I724fb5cfa7961d68c7011255d4ed5c2c89974566
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168764
Comment 2 Commit Notification 2025-08-23 11:58:01 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/14e542d58778963df461965f129286fc75459d3b

tdf#168008 XTextRangeCompare doesn't throw when ranges are in different texts

It will be available in 26.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 3 Commit Notification 2025-08-24 19:28:37 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-25-8":

https://git.libreoffice.org/core/commit/f72b23deb73542c60984e8cc6390c62b8b9370c7

tdf#168008 XTextRangeCompare doesn't throw when ranges are in different texts

It will be available in 25.8.1.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2025-08-26 15:51:07 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/ee60c7a37b11eba85e05ef317ef91c32c89e0bbd

tdf#168008 XTextRangeCompare doesn't throw when ranges are in different texts

It will be available in 25.2.7.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.