Bug 125421 - The Basic function EqualUnoObjects wrongly returns False for two variables having assigned the same object by different ways of access.
Summary: The Basic function EqualUnoObjects wrongly returns False for two variables ha...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
3.3.0 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Macro
  Show dependency treegraph
 
Reported: 2019-05-21 13:52 UTC by Wolfgang Jäger
Modified: 2023-05-13 18:40 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
The example announced in the report (10.18 KB, application/vnd.oasis.opendocument.spreadsheet)
2019-05-21 13:52 UTC, Wolfgang Jäger
Details
EqualUnoObjects - working example with controls (9.88 KB, application/vnd.oasis.opendocument.spreadsheet)
2019-05-22 17:18 UTC, Oliver Brinzing
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Wolfgang Jäger 2019-05-21 13:52:47 UTC
Created attachment 151563 [details]
The example announced in the report

(E.g.)
Having a sheet with a shape anchored to a cell we can get the cell using the sheet's method getCellByPosition. We can get the same cell object via the shape's .Anchor property.
Now we can apply the function EqualUnoObjects() to the two representations of the same object.
Expected result: True
Actual result:   False
Thorough inspection of both representations in the IDE doesn't show any differences. Same (respective) result for
EqualUnoObjects(ThisComponent.Sheets.GetByIndex(0), _
ThisComponent.Sheets.GetByName("Sheet1"))

If the function not was implemented for the comparison of ANY kind of objects, but only for UnoStruct e.g. this should be explicitly stated somewhere (since I assume that a respective change of the name not is acceptable). The result in cases of undue application concerning the type of objects should be an error then instead of the nwrong (at least gravely misleading) False.

Testing was done with OOo V3.2 and with LibO V 6.2.3.2

The behaviour obviously is common heritage of LibO and AOO.

See attached demo.
Comment 2 Julien Nabet 2019-05-21 19:59:06 UTC
On pc Debian x86-64 with master sources updated today, I could reproduce this.

Since in this part:
   3171     if( x1 == x2 )
   3172     {
   3173         refVar->PutBool( true );
   3174     }

x1 isn't considered as == to x2, refVar stays at false.

Now I don't know how to fix this or if we should fix this.
Indeed, I suppose it may have impacts on existing macros.
Comment 3 Wolfgang Jäger 2019-05-21 22:55:22 UTC
I should subjoin that even the expression 

EqualUnoObjects(ThisComponent.Sheets.GetByIndex(0), ThisComponent.Sheets.GetByIndex(0))

will return False.
Comment 4 Oliver Brinzing 2019-05-22 17:18:59 UTC
Created attachment 151602 [details]
EqualUnoObjects - working example with controls

adding a working example, searching a control on drawpage
Comment 5 Wolfgang Jäger 2019-06-21 10:51:39 UTC
You may also have a glance at a related post in a forum where sometimes actual discussion occurs: https://forum.openoffice.org/en/forum/viewtopic.php?f=20&t=98435
Comment 6 Mike Kaganski 2020-07-21 09:20:39 UTC
We actually do create a new object each time a range object is requested (see e.g. ScTableSheetsObj::GetObjectByIndex_Impl[1], which implements functionality of XIndexAccess::getByIndex). So at least in case of range objects (which have their range read-only, thus for all uses should be considered "same" when refer to same range), we need some special casing to check if they are objects of the same type (e.g., one could be "sheet", and the other "all cells, but not sheet", and these are different objects), and then refer to the same range.

https://git.libreoffice.org/core/+/1c3eb7e329cd2eaeb83068907ba0c9a5b3ef7852/sc/source/ui/unoobj/docuno.cxx#3577
Comment 7 QA Administrators 2022-07-22 03:43:50 UTC Comment hidden (obsolete)
Comment 8 Wolfgang Jäger 2023-05-13 17:44:50 UTC
Checked with V 7.5.3.2 under Win10

Behaviour unchanged.
Comment 9 Wolfgang Jäger 2023-05-13 18:40:14 UTC
(In reply to Mike Kaganski from comment #6)
> We actually do create a new object each time a range object is requested
> (see e.g. ScTableSheetsObj::GetObjectByIndex_Impl[1], which implements
> functionality of XIndexAccess::getByIndex). So at least in case of range
> objects (which have their range read-only, thus for all uses should be
> considered "same" when refer to same range), ...
  ... we need some special casing to
> check if they are objects of the same type (e.g., one could be "sheet", and
> the other "all cells, but not sheet", ...
  ... and these are different objects), and
> then refer to the same range.
> 
> https://git.libreoffice.org/core/+/1c3eb7e329cd2eaeb83068907ba0c9a5b3ef7852/
> sc/source/ui/unoobj/docuno.cxx#3577

Thanks. 
I can't start to study and analyze the complex C++ code (I never understood sufficiently nor ever liked). 

As a frequent user of the API I would, however, expect that things are consistent to a degree allowing for a sufficient understanding either by a kind of self-explanation and educated reasoning or by well structured documentation. 

That there are objects of different types in a sense as underlying the above example without giving the user reliable information about it is just confusion, imo. 

I'm told that only service names are assured to be stable. OK. But if so there must be a service helping to distinguish "different object types" in every case. Otherwise implementation names must get assured stability, and must be applied in a way offering the mentioned functionality. 

Also a kind of bundling or "merging" services in a way that results in facts like EqualUNOobjects(cellObject, cellObject.Text)=True (same "object type"?) is evil if not at least there are reliable means to make the needed distinctions in a different way. 

An API will always partly be useless or create errors if its usage requires full understanding of the core code. 

If "object types" are actually defined by their BUNDLING of services, these types must have stable names, and their bundling (including the surprising "identities") must be documented.