Bug 155822

Summary: Method findAll() of com.sun.star.util.XSearchable may return NULL though specified to return XIndexAccess container.
Product: LibreOffice Reporter: Wolfgang Jäger <jag>
Component: BASICAssignee: Not Assigned <libreoffice-bugs>
Status: NEW ---    
Severity: normal CC: mentoring
Priority: medium Keywords: difficultyBeginner, easyHack, skillCpp
Version: 3.3.0 release   
Hardware: All   
OS: All   
Whiteboard:
Crash report or crash signature: Regression By:
Attachments: The announced demo

Description Wolfgang Jäger 2023-06-13 19:42:09 UTC
Created attachment 187895 [details]
The announced demo

XIndexAccess containers can well be empty. The .Count property then is 0.

The result of a .findAll() with XSearchable is one of the cases where a result of type XIndexAccess is specified, but NO such result is returned if nothing was found. Instead of setting .Count to 0, in this case the NULL object is returned. 

It may factually be impossible to fix the bug because old running code would be broken this way. However, the API documentation should give a related hint, and list the cases where a NULL ob ject will be returned, while a XIndexAccess object should be expected.

Thare is a demonstrating example attched.
Comment 1 Mike Kaganski 2023-06-13 20:02:12 UTC
https://opengrok.libreoffice.org/xref/core/sc/source/ui/unoobj/cellsuno.cxx?r=3e7ff2a9&mo=189177&fi=3757#3757

introduced in the initial import.

It looks reasonable to throw an error when the initial check (pDocShell && xDesc.is()) fails, and if it passes, it seems possible to create an empty ScRangeList right away, and create the returned ScCellRangesObj with it unconditionally before return.

The easyhack needs a unit test.