Bug 157915 - Error UNO type of C++ when running a Basic macro with instruction commitChanges for org.openoffice.Office.Commands/Execute/Disabled
Summary: Error UNO type of C++ when running a Basic macro with instruction commitChang...
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
7.4.0.0 alpha0+
Hardware: x86-64 (AMD64) All
: high major
Assignee: Not Assigned
URL:
Whiteboard: target:24.2.0 target:7.6.5
Keywords: bibisected, bisected, regression
Depends on:
Blocks: Macro-UNOAPI
  Show dependency treegraph
 
Reported: 2023-10-25 08:53 UTC by Isatis34
Modified: 2023-12-11 17:48 UTC (History)
4 users (show)

See Also:
Crash report or crash signature:


Attachments
Disable commands BASIC sample (15.42 KB, application/vnd.oasis.opendocument.text)
2023-10-26 09:24 UTC, Alain Romedenne
Details
Version (234 bytes, text/plain)
2023-10-27 07:34 UTC, B. Antonio Fernández
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Isatis34 2023-10-25 08:53:50 UTC
Description:
Hello,

I'm running this marcro :

Sub disableAboutCommand()
	disableCommand("About")
End Sub

Function disableCommand( cmd As String )
Dim keyNode As Object ' com.sun.star.configuration.Configuration(Update)Access '

	With GlobalScope.Basiclibraries
		If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
	End With

	' Set the root path for our configuration access
	keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Commands/Execute/Disabled", True)

	newCmd = keyNode.CreateInstanceWithArguments( Array() )		
	newCmd.setPropertyValue( "Command", cmd ) ' Add cmd to disabled command list 
	keyNode.insertByName( "Command-" & cmd, newCmd) ' name must be unique
	
	keyNode.commitChanges ' flush changes
End Function

I get this error on the line "keyNode.commitChanges" :
Erreur d'exécution BASIC.
Une exception s'est produite : 
Type: com.sun.star.uno.RuntimeException
Message: [mscx_uno bridge error] UNO type of C++ exception unknown: "std.system_error", RTTI-name=".?AVsystem_error@std@@"!.

After, LibreOffice stay open. The About menu is still visible.
If I close LibreOffice, the About menu has disappear.


Steps to Reproduce:
1. Copy/paste the macro in a module
2. Run disableAboutCommand
3.

Actual Results:
Error message

Erreur d'exécution BASIC.
Une exception s'est produite : 
Type: com.sun.star.uno.RuntimeException
Message: [mscx_uno bridge error] UNO type of C++ exception unknown: "std.system_error", RTTI-name=".?AVsystem_error@std@@"!.


Expected Results:
No error and Menu hidden


Reproducible: Always


User Profile Reset: No

Additional Info:
Version: 7.5.3.2 (X86_64) / LibreOffice Community
Build ID: 9f56dff12ba03b9acd7730a5a481eea045e468f3
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: fr-FR (fr_FR); UI: fr-FR
Calc: CL threaded
Comment 1 Isatis34 2023-10-25 09:52:43 UTC
Hello, 

I just update my LO to 7.6.2.1


Version: 7.6.2.1 (X86_64) / LibreOffice Community
Build ID: 56f7684011345957bbf33a7ee678afaf4d2ba333
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: fr-FR (fr_FR); UI: fr-FR
Calc: CL threaded

I have the same error.

Thanks
Comment 2 Isatis34 2023-10-25 11:56:27 UTC
Hello

I try this macro with LibreOffice 7.6.2.1 on CentOS and LO crashed.
Comment 3 Alain Romedenne 2023-10-26 09:22:56 UTC
I reproduced the problem using:

Version: 7.6.2.1 (X86_64) / LibreOffice Community
Build ID: 56f7684011345957bbf33a7ee678afaf4d2ba333
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: fr-FR (fr_FR); UI: en-US
Calc: CL threaded

The attached doc reproduces the exception, whilst it functions properly in the following context:

Version: 7.2.5.2 (x86) / LibreOffice Community
Build ID: 499f9727c189e6ef3471021d6132d4c694f357e5
CPU threads: 4; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: fr-FR (fr_FR); UI: en-US
Calc: CL

I assume it's a regression in .commitChanges() method

the attached doc is a BASIC port of wiki Java example at:
https://wiki.documentfoundation.org/Documentation/DevGuide/Writing_UNO_Components#Disable_Commands
Comment 4 Alain Romedenne 2023-10-26 09:24:21 UTC
Created attachment 190436 [details]
Disable commands BASIC sample
Comment 5 elmau 2023-10-26 17:21:40 UTC
I can reproduced the problem in:

Version: 7.5.7.1 (X86_64) / LibreOffice Community
Build ID: 50(Build:1)
CPU threads: 16; OS: Linux 6.5; UI render: default; VCL: gtk3
Locale: es-MX (en_US.UTF-8); UI: en-US
7.5.7-3
Calc: threaded
Comment 6 Lobaluna 2023-10-27 05:31:08 UTC
Version: 7.6.2.1 (X86_64) / LibreOffice Community
Build ID: 56f7684011345957bbf33a7ee678afaf4d2ba333
CPU threads: 8; OS: Linux 5.4; UI render: default; VCL: gtk3
Locale: en-US (en_US.UTF-8); UI: en-US
Calc: threaded

I ran the macro from the IDE, no messages at all. But the menus freezed and
LibreOffice crashed.
Comment 7 B. Antonio Fernández 2023-10-27 07:34:36 UTC
Created attachment 190446 [details]
Version

I get the same error but menu entry is disable
Version: 7.5.8.1 (X86_64) / LibreOffice Community
Build ID: a3cc32c5bcaabeae7ab60e12c44c40a7d8d36345
CPU threads: 8; OS: Windows 10.0 Build 19045; UI render: Skia/Raster; VCL: win
Locale: es-ES (es_ES); UI: es-ES
Calc: CL threaded
Comment 8 elmau 2023-10-30 01:07:42 UTC
Reproducible with code Python too.
Comment 9 Stéphane Guillou (stragu) 2023-11-28 15:18:13 UTC
There could be a couple of different things in this report, but here's my test results:

With attachment 190436 [details], no freeze in:

Version: 7.3.7.2 / LibreOffice Community
Build ID: e114eadc50a9ff8d8c8a0567d6da8f454beeb84f
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US

Reproduced the freeze in:

Version: 7.4.7.2 / LibreOffice Community
Build ID: 723314e595e8007d3cf785c16538505a1c878ca5
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US

Still freezing in recent trunk build:

Version: 24.2.0.0.alpha1+ (X86_64) / LibreOffice Community
Build ID: 5589659829f8a1cef8ca1c8a468732105bbe231b
CPU threads: 8; OS: Linux 5.15; UI render: default; VCL: gtk3
Locale: en-AU (en_AU.UTF-8); UI: en-US

Bibisected with linux-64-7.4 to first bad build commit [97472a721e8176c6e6309166e421dab573b0d780] which points to core commit:

commit 1576ef8532cf2cea2da361db9c5707f1994e65e2
author	Noel Grandin 	Thu Dec 23 18:40:44 2021 +0200
committer	Noel Grandin 	Fri Dec 24 19:50:02 2021 +0100
osl::Mutex->std::mutex in SvtCommandOptions
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127413

Noel, can you please have a look?

To be clear, I tested the attachment with a new profile before and after the commit, with Low macro security setting. Since the commit, LO freezes after pressing OK on the dialog with message:
> "Ok, dispatch object for .uno:Quit"
Comment 10 Noel Grandin 2023-12-06 13:55:45 UTC
So I have a fix for part of this, the part the Isatis34 reported, and which primarily shows up on windows.

However, on Linux, when testing with the test document kindly supplied by Alain, we have another problem: So the about dialog is async. But the message box is not. Which means that, depending on timing, the AboutDialog could end up above the message box, even though the message-box run loop is top of stack. And I cant make the message box async, because the basic evaluation loop is synchronous, and expects the message box to be done, when the message box function returns.

So even though I have fixed the original problem, the test macro is still going to freeze LO on Linux, and that is something I cannot fix - that is a broader problem  that will affect the interaction of any asynchronous dialog and a Basic message box.
Comment 11 Commit Notification 2023-12-06 19:27:51 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "master":

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

tdf#157915 Error when running a Basic macro with instruction commitChanges

It will be available in 24.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 12 Commit Notification 2023-12-08 10:29:45 UTC
Noel Grandin committed a patch related to this issue.
It has been pushed to "libreoffice-7-6":

https://git.libreoffice.org/core/commit/5f37e4769420e216e95225a1de0c6074e97ad62b

tdf#157915 Error when running a Basic macro with instruction commitChanges

It will be available in 7.6.5.

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 13 Isatis34 2023-12-11 13:09:40 UTC
Hello,

I tested Version: 7.6.5.0.0+ (X86_64) / LibreOffice Community
Build ID: 4073f13330600d3efc25fc25450f9f635c6e74b2
CPU threads: 2; OS: Linux 3.10; UI render: default; VCL: gtk3
Locale: fr-FR (fr_FR.UTF-8); UI: en-US
Calc: threaded

There is no crash now, many thanks.

So now, this code works, When disableCommand stops, the menu About is not visible. :

Sub disableAboutCommand()
	disableCommand("About")
End Sub
Function disableCommand( cmd As String )
Dim keyNode As Object ' com.sun.star.configuration.Configuration(Update)Access '

	With GlobalScope.Basiclibraries
		If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
	End With

	' Set the root path for our configuration access
	keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Commands/Execute/Disabled", True)

	newCmd = keyNode.CreateInstanceWithArguments( Array() )		
	newCmd.setPropertyValue( "Command", cmd ) ' Add cmd to disabled command list 
	keyNode.insertByName( "Command-" & cmd, newCmd) ' name must be unique
	
	keyNode.commitChanges ' flush changes
End Function


I try the inverse :

Sub enableAboutCommand()
	enableCommand("About")
End Sub

Function enableCommand( cmd As String )
'on error resume next

	Dim keyNode As Object ' com.sun.star.configuration.Configuration(Update)Access '

  	' Set the root path for our configuration access
	With GlobalScope.Basiclibraries
        If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
    End With
    keyNode = Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Commands/Execute/Disabled", True)

	newCmd = keyNode.CreateInstanceWithArguments( Array() )		

	newCmd.setPropertyValue( "Command", cmd ) ' Add cmd to disabled command list 

	keyNode.removeByName( "Command-" & cmd) ' name must be unique

	keyNode.commitChanges ' flush changes

End Function 

This code doesn't crash, but I've to restart LibreOffice to hae About menu visible.
Comment 14 Alain Romedenne 2023-12-11 17:48:18 UTC
(In reply to Isatis34 from comment #13)
> Hello,
> 
> I tested Version: 7.6.5.0.0+ (X86_64) / LibreOffice Community
> Build ID: 4073f13330600d3efc25fc25450f9f635c6e74b2
> CPU threads: 2; OS: Linux 3.10; UI render: default; VCL: gtk3
> Locale: fr-FR (fr_FR.UTF-8); UI: en-US
> Calc: threaded
> 
> There is no crash now, many thanks.
> 
> So now, this code works, When disableCommand stops, the menu About is not
> visible. :
> 
> Sub disableAboutCommand()
> 	disableCommand("About")
> End Sub
> Function disableCommand( cmd As String )
> Dim keyNode As Object '
> com.sun.star.configuration.Configuration(Update)Access '
> 
> 	With GlobalScope.Basiclibraries
> 		If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
> 	End With
> 
> 	' Set the root path for our configuration access
> 	keyNode =
> Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Commands/Execute/
> Disabled", True)
> 
> 	newCmd = keyNode.CreateInstanceWithArguments( Array() )		
> 	newCmd.setPropertyValue( "Command", cmd ) ' Add cmd to disabled command
> list 
> 	keyNode.insertByName( "Command-" & cmd, newCmd) ' name must be unique
> 	
> 	keyNode.commitChanges ' flush changes
> End Function
> 
> 
> I try the inverse :
> 
> Sub enableAboutCommand()
> 	enableCommand("About")
> End Sub
> 
> Function enableCommand( cmd As String )
> 'on error resume next
> 
> 	Dim keyNode As Object '
> com.sun.star.configuration.Configuration(Update)Access '
> 
>   	' Set the root path for our configuration access
> 	With GlobalScope.Basiclibraries
>         If Not .IsLibraryLoaded("Tools") Then .LoadLibrary("Tools")
>     End With
>     keyNode =
> Tools.Misc.GetRegistryKeyContent("org.openoffice.Office.Commands/Execute/
> Disabled", True)
> 
> 	newCmd = keyNode.CreateInstanceWithArguments( Array() )		
> 
> 	newCmd.setPropertyValue( "Command", cmd ) ' Add cmd to disabled command
> list 
> 
> 	keyNode.removeByName( "Command-" & cmd) ' name must be unique
> 
> 	keyNode.commitChanges ' flush changes
> 
> End Function 
> 
> This code doesn't crash, but I've to restart LibreOffice to hae About menu
> visible.

This behaviour is already reported in bug#158157