Bug 92770 - thisComponent is not valid during "Open Document" at startup in non-document macro
Summary: thisComponent is not valid during "Open Document" at startup in non-document ...
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
4.4.2.2 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords: bibisected, bisected, regression
Depends on:
Blocks: VclPtr
  Show dependency treegraph
 
Reported: 2015-07-15 17:24 UTC by Lionel Elie Mamane
Modified: 2019-08-10 07:27 UTC (History)
10 users (show)

See Also:
Crash report or crash signature:


Attachments
reproduction case (4.07 KB, application/vnd.oasis.opendocument.database)
2015-07-15 17:24 UTC, Lionel Elie Mamane
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lionel Elie Mamane 2015-07-15 17:24:05 UTC
Created attachment 117261 [details]
reproduction case

When:

 - LibreOffice is started with instruction to open document foo.odb
   (for example, type in a shell "/path/to/soffice foo.odb")
AND
 - in foo.odb, the "Open Document" event is bound to a macro "OnOpen"
AND
 - the macro "OnOpen" is not saved in foo.odb, but in "My Macros"
   OR calls (without delay, without a MsgBox before, etc)
      a macro "Go" that is saved in "My Macros"
AND
 - OnOpen/Go tries to use thisComponent

THEN

thisComponent is not set to a valid value. E.g., XRay cannot introspect it, it doesn't have a supportsService method, ...BUT isEmpty(thisComponent) is *false*.

Just adding a "wait 5000" solves the problem, which hints at a race condition, or a wrong order of initialisation (if the wait() makes a Yield/DoEvents).

If the macro OnOpen, saved in the .odb file, uses thisComponent directly, then it works.
If the macro is executed *after* the document is finished opening, then it works.
If one first starts LibreOffice and *then* opens the file through the UI, then it works.

Regression with respect to 5.0 (my GNU/Linux dev tree), 4.4 (Windows TDF build) and 4.3 (Debian package).


Reproduction steps:

Put in "My Macros" the following (beware bugzilla's word wrap):

Sub showThisComponent
	MsgBox "Macro in ""My Macros"": " & _
            thisComponent.supportsService("com.sun.star.document.OfficeDocument")
End Sub


Set Macro security to medium or lower.


CLOSE LIBREOFFICE


Open the attached odb file by starting libreoffice with as argument /path/to/odb_file.
Accept macros if prompted.


Actual result: error message

  BASIC runtime error.
  Property or method not found: supportsService.

Expected result (and actual result with previous versions): message box saying:

  Macro in "My Macros": True
Comment 1 Noel Power 2015-07-16 08:52:19 UTC
(In reply to Lionel Elie Mamane from comment #0)
> Created attachment 117261 [details]
> reproduction case
> 
> When:
> 
>  - LibreOffice is started with instruction to open document foo.odb
>    (for example, type in a shell "/path/to/soffice foo.odb")
> AND
>  - in foo.odb, the "Open Document" event is bound to a macro "OnOpen"
> AND
>  - the macro "OnOpen" is not saved in foo.odb, but in "My Macros"
>    OR calls (without delay, without a MsgBox before, etc)
>       a macro "Go" that is saved in "My Macros"
> AND
>  - OnOpen/Go tries to use thisComponent
> 
> THEN
> 
> thisComponent is not set to a valid value. E.g., XRay cannot introspect it,
> it doesn't have a supportsService method, ...BUT isEmpty(thisComponent) is
> *false*.
> 

Unlikely this is anything to do with basic but rather something has changed in the framework code which creates/sets the 'ThisComponent' value. iirc basics ThisComponent value is set in objxstor.c as part of the opening of a document. In this case it seems like the object behind 'ThisComponent' at this point is partially contructed or maybe some sort of placeholder, you'll have to dig deeper in the framework code I expect
Comment 2 pierre-yves samyn 2015-07-24 13:36:07 UTC
Hi

I reproduce on Windows 7/64 & Version: 5.0.0.3
Build ID: f79b5ba13f5e6cbad23f8038060e556217e66632
Locale: fr-FR (fr_FR)

I set status to New

I also get problems with macro on open document (see bug 92916). May be related ?

Regards
Pierre-Yves
Comment 3 raal 2015-10-14 15:34:05 UTC
I can confirm with LO 4.4.2, linux
Comment 4 raal 2015-12-03 15:25:20 UTC
This seems to have begun at the below commit.
Adding Cc: to Michael Meeks ; Could you possibly take a look at this one? Thanks

bibisect-win32-5.1:
ba5c12eeb1977bd3f7466df16a94b4c6f9523f6e is the first bad commit
commit ba5c12eeb1977bd3f7466df16a94b4c6f9523f6e
Author: Norbert Thiebaud <nthiebaud@gmail.com>
Date:   Tue Jul 14 14:13:07 2015 -0700

    source sha:7aae8772aa18744cb1bbd8348272be99cc882c47
    source sha:7aae8772aa18744cb1bbd8348272be99cc882c47

author    Michael Meeks <michael.meeks@collabora.com>    2015-06-05 15:37:49 (GMT)
committer    Michael Meeks <michael.meeks@collabora.com>    2015-06-05 19:45:12 (GMT)
commit    7aae8772aa18744cb1bbd8348272be99cc882c47 (patch)
Clear VclPtr instance reference on removed UserEvents.

Some crashers during bibisecting, I marked them as "git bisect bad"
Comment 5 Robinson Tryon (qubit) 2015-12-13 11:13:25 UTC Comment hidden (obsolete)
Comment 6 Björn Michaelsen 2016-04-16 16:56:21 UTC
blocks vclptr as per comment 4
Comment 7 Caolán McNamara 2016-05-26 11:42:48 UTC
lionel, does this still fail for you. For me, assuming I'm doing it right. It works for me on 5.0, 5.1 and master
Comment 8 Lionel Elie Mamane 2016-05-26 11:56:16 UTC
(In reply to Caolán McNamara from comment #7)
> lionel, does this still fail for you. For me, assuming I'm doing it right.
> It works for me on 5.0, 5.1 and master

Yes, it still fails for me with:
 5.1.3.2 (Debian package) - macro security medium (and "Security Warning / Enable Macros" prompt)
 5.2.0.0.alpha1+ (my debug build) as of 18 may 2016 - macro security medium (and "Security Warning / Enable Macros" prompt)

It does *not* fail for me with:

 5.1.3.2 (Debian package) - macro security low (and *no* "Security Warning / Enable Macros" prompt)
 5.2.0.0.alpha1+ (my debug build) as of 18 may 2016 - macro security low (and *no* "Security Warning / Enable Macros" prompt)

It also fails with 5.1.3.2, if I start LibreOffice, get the start screen and open attachment 117261 [details].

It does *not* fail with 5.1.3.2 if I start LibreOffice, get the start screen, open a blank writer document and then open attachment 117261 [details] (from menu file / "recent documents")
Comment 9 Julien Nabet 2016-10-23 12:09:43 UTC
On pc Debian x86-64 with master sources updated today (+enable-dbgutil), I could reproduce this.

I noticed this on console:
warn:xmloff.core:20330:1:xmloff/source/core/xmlimp.cxx:1011: exception caught
warn:legacy.osl:20330:1:xmloff/source/core/xmlimp.cxx:1012: DBG_UNHANDLED_EXCEPTION in virtual void SvXMLImport::setTargetDocument(const com::sun::star::uno::Reference<com::sun::star::lang::XComponent>&)
    type: com.sun.star.lang.NotInitializedException
    context: N8dbaccess17ODatabaseDocumentE

warn:xmloff.core:20330:1:xmloff/source/core/xmlimp.cxx:1011: exception caught
warn:legacy.osl:20330:1:xmloff/source/core/xmlimp.cxx:1012: DBG_UNHANDLED_EXCEPTION in virtual void SvXMLImport::setTargetDocument(const com::sun::star::uno::Reference<com::sun::star::lang::XComponent>&)
    type: com.sun.star.lang.NotInitializedException
    context: N8dbaccess17ODatabaseDocumentE

warn:xmloff.core:20330:1:xmloff/source/core/xmlimp.cxx:1011: exception caught
warn:legacy.osl:20330:1:xmloff/source/core/xmlimp.cxx:1012: DBG_UNHANDLED_EXCEPTION in virtual void SvXMLImport::setTargetDocument(const com::sun::star::uno::Reference<com::sun::star::lang::XComponent>&)
    type: com.sun.star.lang.NotInitializedException
    context: N8dbaccess17ODatabaseDocumentE

warn:legacy.osl:20330:7:basctl/source/basicide/doceventnotifier.cxx:127: DocumentEventNotifier::Impl::notifyEvent: illegal source document!
warn:legacy.osl:20330:7:basctl/source/basicide/doceventnotifier.cxx:127: DocumentEventNotifier::Impl::notifyEvent: illegal source document!
warn:legacy.osl:20330:7:basctl/source/basicide/doceventnotifier.cxx:127: DocumentEventNotifier::Impl::notifyEvent: illegal source document!
Comment 10 Buovjaga 2017-05-19 14:31:07 UTC
Tried with Xray 5.2. It works for me: Macro in "My Macros": True

Could it be this work fixed it: bug 105735 / bug 107029 ?

Arch Linux 64-bit, KDE Plasma 5
Version: 5.5.0.0.alpha0+
Build ID: cee02e81cd3b55fb46eacf5db5713e8bf4363bcd
CPU threads: 8; OS: Linux 4.10; UI render: default; VCL: kde4; 
Locale: fi-FI (fi_FI.UTF-8); Calc: group
Built on May 19th 2017
Comment 11 Lionel Elie Mamane 2017-05-19 15:49:47 UTC
(In reply to Buovjaga from comment #10)
> Tried with Xray 5.2. It works for me: Macro in "My Macros": True

> Could it be this work fixed it: bug 105735 / bug 107029 ?

From reading these bugs, I think not.

Retested and reproduced with

Version: 5.2.5.1
Build ID: 1:5.2.5-2
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk3; 
Locale: en-GB (en_GB.utf8); Calc: group

Version: 5.3.4.0.0+
Build ID: (Lionel's development build; updated to
 commit 8501821f3b5ad541c40b5465aab000a6960b97ba
 Author:     Katarina Behrens <Katarina.Behrens@cib.de>
 AuthorDate: Wed May 3 16:55:00 2017 +0200
 Commit:     Caolán McNamara <caolanm@redhat.com>
 CommitDate: Tue May 9 09:50:21 2017 +0200)
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk3; Layout Engine: new;
Locale: en-GB (en_GB.utf8); Calc: group

but NOT reproduced with any of:

Version: 5.3.4.0.0+
Build ID: 5756d3d5bd2175335ac302aaa806fd5f2277f564
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk2; Layout Engine: new; 
TinderBox: Linux-rpm_deb-x86_64@70-TDF, Branch:libreoffice-5-3, Time: 2017-05-19_06:34:54
Locale: en-GB (en_GB.utf8); Calc: group

Version: 5.3.3.2
Build ID: 3d9a8b4b4e538a85e0782bd6c2d430bafe583448
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk2; Layout Engine: new; 
Locale: en-GB (en_GB.utf8); Calc: group

Version: 5.3.2.2
Build ID: 6cd4f1ef626f15116896b1d8e1398b56da0d0ee1
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk2; Layout Engine: new; 
Locale: en-GB (en_GB.utf8); Calc: group

Version: 5.5.0.0.alpha0+
Build ID: d880df3a44497cdec49017538a9d38d48e543bad
CPU threads: 8; OS: Linux 4.9; UI render: default; VCL: gtk2; 
TinderBox: Linux-rpm_deb-x86_64@70-TDF, Branch:master, Time: 2017-05-19_07:51:21
Locale: en-GB (en_GB.utf8); Calc: group


Hmm... Might be linked to gtk3, or might be fixed. More testing needed.
Comment 12 Lionel Elie Mamane 2017-05-19 16:08:55 UTC
Nah, using SAL_USE_VCLPLUGIN=gtk does not make it disappear.

My local build is with --enable-dbgutil... Is that the difference? But the Debian package that I test is a release build...

Reproduced with

(TDF build)
Version: 5.2.7.2
Build ID: 2b7f1e640c46ceb28adf43ee075a6e8b8439ed10
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk2; 
Locale: en-GB (en_GB.utf8); Calc: group

I tried again several times with

Version: 5.3.2.2
Build ID: 6cd4f1ef626f15116896b1d8e1398b56da0d0ee1
CPU Threads: 8; OS Version: Linux 4.9; UI Render: default; VCL: gtk2; Layout Engine: new; 
Locale: en-GB (en_GB.utf8); Calc: group


Often it works, sometimes not. So it definitely smells like a race condition.

Ah, now reproduced with

Version: 5.5.0.0.alpha0+
Build ID: d880df3a44497cdec49017538a9d38d48e543bad
CPU threads: 8; OS: Linux 4.9; UI render: default; VCL: gtk2; 
TinderBox: Linux-rpm_deb-x86_64@70-TDF, Branch:master, Time: 2017-05-19_07:51:21
Locale: en-GB (en_GB.utf8); Calc: group

after several tries... like 10.

Ah, I found a way to reproduce each time:


settings: medium security, giving a warning and a choice "enable macros" or "disable macros".

$ /opt/libreofficedev5.5/program/soffice attachment_117261
# give focus to another non-LibreOffice window
# give focus back to security warning window WITHOUT GOING THROUGH focus to LibreOffice main window (which would "pass" its focus to the security warning window)
# click "Enable Macros"


On the other hand, this *always* works (bug does not appear):

$ /opt/libreofficedev5.5/program/soffice attachment_117261
# give focus to another non-LibreOffice window
# give focus back LibreOffce main window; it "passes" its focus to the security warning window
# click "Enable Macros"
Comment 13 QA Administrators 2018-05-20 02:33:09 UTC
** Please read this message in its entirety before responding **

To make sure we're focusing on the bugs that affect our users today, LibreOffice QA is asking bug reporters and confirmers to retest open, confirmed bugs which have not been touched for over a year.

There have been thousands of bug fixes and commits since anyone checked on this bug report. During that time, it's possible that the bug has been fixed, or the details of the problem have changed. We'd really appreciate your help in getting confirmation that the bug is still present.

If you have time, please do the following:

Test to see if the bug is still present with the latest version of LibreOffice from https://www.libreoffice.org/download/

If the bug is present, please leave a comment that includes the information from Help - About LibreOffice.
 
If the bug is NOT present, please set the bug's Status field to RESOLVED-WORKSFORME and leave a comment that includes the information from Help - About LibreOffice.

Please DO NOT

Update the version field
Reply via email (please reply directly on the bug tracker)
Set the bug's Status field to RESOLVED - FIXED (this status has a particular meaning that is not 
appropriate in this case)


If you want to do more to help you can test to see if your issue is a REGRESSION. To do so:
1. Download and install oldest version of LibreOffice (usually 3.3 unless your bug pertains to a feature added after 3.3) from http://downloadarchive.documentfoundation.org/libreoffice/old/

2. Test your bug
3. Leave a comment with your results.
4a. If the bug was present with 3.3 - set version to 'inherited from OOo';
4b. If the bug was not present in 3.3 - add 'regression' to keyword


Feel free to come ask questions or to say hello in our QA chat: https://kiwiirc.com/nextclient/irc.freenode.net/#libreoffice-qa

Thank you for helping us make LibreOffice even better for everyone!

Warm Regards,
QA Team

MassPing-UntouchedBug
Comment 14 Buovjaga 2019-08-09 18:15:58 UTC
I get
BASIC runtime error.
Variable not defined.

for showThisComponent() even when opening the file with Low macro security setting.

Lionel: can you please re-test? This report is one of the few still remaining in the VclPtr meta bug.

Arch Linux 64-bit
Version: 6.4.0.0.alpha0+
Build ID: 37fc9f51a8de11d40632e8cda17ccf1fa4b1f503
CPU threads: 8; OS: Linux 5.2; UI render: default; VCL: gtk3; 
Locale: fi-FI (fi_FI.UTF-8); UI-Language: en-US
Calc: threaded
Built on 6 August 2019
Comment 15 Lionel Elie Mamane 2019-08-09 21:50:29 UTC
Reproduced on 6.3.0.4 (Debian package).

(In reply to Buovjaga from comment #14)
> I get
> BASIC runtime error.
> Variable not defined.
> 
> for showThisComponent() even when opening the file with Low macro security
> setting.

I think you didn't follow the following step in the reproduction instructions:

Put in "My Macros" the following (beware bugzilla's word wrap):

Sub showThisComponent
	MsgBox "Macro in ""My Macros"": " & _
            thisComponent.supportsService("com.sun.star.document.OfficeDocument")
End Sub
Comment 16 Buovjaga 2019-08-10 07:27:39 UTC
(In reply to Lionel Elie Mamane from comment #15)
> Reproduced on 6.3.0.4 (Debian package).
> I think you didn't follow the following step in the reproduction
> instructions:
> 
> Put in "My Macros" the following (beware bugzilla's word wrap):
> 
> Sub showThisComponent
> 	MsgBox "Macro in ""My Macros"": " & _
>            
> thisComponent.supportsService("com.sun.star.document.OfficeDocument")
> End Sub

You are right, I repro as well after doing this.