Bug 151766 - Using Java UNO API freezes LibreOffice on M1 MacBook Pro
Summary: Using Java UNO API freezes LibreOffice on M1 MacBook Pro
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
unspecified
Hardware: Other macOS (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Java-Runtime-JRE
  Show dependency treegraph
 
Reported: 2022-10-26 11:06 UTC by Simon Muschel
Modified: 2022-12-27 21:58 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
Sample Code (1014 bytes, text/plain)
2022-10-26 11:06 UTC, Simon Muschel
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simon Muschel 2022-10-26 11:06:40 UTC
Created attachment 183279 [details]
Sample Code

Problem: LibreOffice freezes/becomes unresponsive when started (or being controlled) from a Java Application using UNO API (libreoffice.jar). This reproducibly happens for calls to loadComponentFromURL but also on dispose-Calls (lines 17 and 19 in sample).

The attached sample code was used to demonstrate this behavior.

Hardware/OS info: M1 MacBook Pro, both Monterey and Ventura were used.
LibreOffice versions: multiple versions from 7.2.x, 7.3.x and latest 7.4; all M1 architecture

Test cases:

1. LibreOffice is not running. The attached test class is executed and tries to open an empty Writer document. The call to 'loader.loadComponentFromURL(...)' creates an empty LibreOffice window, but not the Writer content (only a gray window is displayed, LibreOffice is unresponsive). Have to kill the process.

2. LibreOffice is started manually, a Writer document is opened manually. The test class successfully opens another empty Writer window. In this case, the sample fails on the dispose call (LibreOffice becomse unresponsive, have to kill process)

Additional info:
Same code works on an Intel MacMini with an older version of LibreOffice (7.0.x, Intel architecture).

I also tried several Intel-architecture versions on the M1 MacBook Pro - until version 7.3.2.2, I could make the sample work. It starts failing from version 7.3.4.1 onwards.
Comment 1 Simon Muschel 2022-10-26 11:30:11 UTC
Sorry, typo in version number: with the Intel architecture versions, the sample works up to version 7.3.3.2 (not 7.3.2.2) and starts failing beginning with 7.3.4.1
Comment 2 Alex Thurgood 2022-10-28 16:17:59 UTC
How is this code supposed to be run ? Do I just download the sample code, add a .java extension to the file name and try and run it from the command line ?
Comment 3 Alex Thurgood 2022-10-28 16:21:17 UTC
FWIW, the many of the people who do bug triaging within the project are not developers/programmers, and this is almost exclusively so on macOS.

There are certainly no paid developers working on macOS specific LO issues, to my knowledge.

In order for it to be tested, we would generally need a greater degree of detail on how to reproduce.
Comment 4 Simon Muschel 2022-11-07 18:36:06 UTC
Thank you for your reply - sorry my description was not precise enough.

Prerequisites for test case:
* M1 Mac (e.g. MacBook Pro)
* Java JDK installation (I used version 17)


Assumptions for the following steps:
* LibreOffice is installed in the standard location (/Applications/LibreOffice.app)
* Java is installed an can be executed from Terminal


Steps to reproduce behavior:
* Download attachment, rename file to Test.java
* Open Terminal, go to folder containing Test.java
* execute command to compile test case (all in one line):

javac -cp /Applications/LibreOffice.app/Contents/Resources/java/libreoffice.jar Test.java

* Execution of previous step should result in creation of file Test.class
* execute command to run test case (all in one line):

java -classpath /Applications/LibreOffice.app/Contents/MacOS/:/Applications/LibreOffice.app/Contents/Resources/java/libreoffice.jar:/Applications/LibreOffice.app/Contents/Resources/java/unoloader.jar:. -Djava.library.path=/Applications/LibreOffice.app/Contents/Frameworks Test


Result:
LibreOffice window opens, but no Writer document is started. LO window stays grayed out. Process has to be terminated.

Expected Result:
LO window opens, a new Writer document is started. After 15 seconds, Writer document/window will be closed. Test case exits.
Comment 5 Mike Little 2022-11-08 06:46:03 UTC
(In reply to Simon Muschel from comment #0)
> Created attachment 183279 [details]
> Sample Code
> 
> Problem: LibreOffice freezes/becomes unresponsive when started (or being
> controlled) from a Java Application using UNO API (libreoffice.jar). This
> reproducibly happens for calls to loadComponentFromURL but also on
> dispose-Calls (lines 17 and 19 in sample).
> 
> The attached sample code was used to demonstrate this behavior.
> 
> Hardware/OS info: M1 MacBook Pro, both Monterey and Ventura were used.
> LibreOffice versions: multiple versions from 7.2.x, 7.3.x and latest 7.4;
> all M1 architecture
> 
> Test cases:
> 
> 1. LibreOffice is not running. The attached test class is executed and tries
> to open an empty Writer document. The call to
> 'loader.loadComponentFromURL(...)' creates an empty LibreOffice window, but
> not the Writer content (only a gray window is displayed, LibreOffice is
> unresponsive). Have to kill the process.
> 
> 2. LibreOffice is started manually, a Writer document is opened manually.
> The test class successfully opens another empty Writer window. In this case,
> the sample fails on the dispose call (LibreOffice becomse unresponsive, have
> to kill process)
> 
> Additional info:
> Same code works on an Intel MacMini with an older version of LibreOffice
> (7.0.x, Intel architecture).
> 
> I also tried several Intel-architecture versions on the M1 MacBook Pro -
> until version 7.3.2.2, I could make the sample work. It starts failing from
> version 7.3.4.1 onwards.

Do I need to download and configure the OpenOffice SDK as I am getting in Eclipse "The import com.sun.star" cannot be resolved...
Comment 6 Simon Muschel 2022-11-08 07:43:32 UTC
(In reply to Mike Little from comment #5)
> (In reply to Simon Muschel from comment #0)
> > Created attachment 183279 [details]
> > Sample Code
> > 
> > Problem: LibreOffice freezes/becomes unresponsive when started (or being
> > controlled) from a Java Application using UNO API (libreoffice.jar). This
> > reproducibly happens for calls to loadComponentFromURL but also on
> > dispose-Calls (lines 17 and 19 in sample).
> > 
> > The attached sample code was used to demonstrate this behavior.
> > 
> > Hardware/OS info: M1 MacBook Pro, both Monterey and Ventura were used.
> > LibreOffice versions: multiple versions from 7.2.x, 7.3.x and latest 7.4;
> > all M1 architecture
> > 
> > Test cases:
> > 
> > 1. LibreOffice is not running. The attached test class is executed and tries
> > to open an empty Writer document. The call to
> > 'loader.loadComponentFromURL(...)' creates an empty LibreOffice window, but
> > not the Writer content (only a gray window is displayed, LibreOffice is
> > unresponsive). Have to kill the process.
> > 
> > 2. LibreOffice is started manually, a Writer document is opened manually.
> > The test class successfully opens another empty Writer window. In this case,
> > the sample fails on the dispose call (LibreOffice becomse unresponsive, have
> > to kill process)
> > 
> > Additional info:
> > Same code works on an Intel MacMini with an older version of LibreOffice
> > (7.0.x, Intel architecture).
> > 
> > I also tried several Intel-architecture versions on the M1 MacBook Pro -
> > until version 7.3.2.2, I could make the sample work. It starts failing from
> > version 7.3.4.1 onwards.
> 
> Do I need to download and configure the OpenOffice SDK as I am getting in
> Eclipse "The import com.sun.star" cannot be resolved...

I did not install the SDK. I guess you'd have to add libreoffice.jar and unoloader.jar from LibreOffice installation to your Eclipse project. If it's easier for you, I can try to provide the test case as a Maven project.
Comment 7 Alex Thurgood 2022-11-08 10:03:19 UTC
Something that requires setting up a Java build environment to build and run a test case is not trivial for the majority of QA triagers, who are volunteers. I don't have such a build setup, so unfortunately can not help here.
Comment 8 Alex Thurgood 2022-11-08 10:04:37 UTC
(In reply to Mike Little from comment #5)


> 
> Do I need to download and configure the OpenOffice SDK as I am getting in
> Eclipse "The import com.sun.star" cannot be resolved...

Same here, and as I don't program or build in any kind of Java environment, this is out of my scope.
Comment 9 Mike Little 2022-11-10 06:44:47 UTC
 I have downloaded the SDK and configured it, but I cannot find the relevant .jar files for the build path [project>build path> Configure Build Path ...

import com.sun.star.beans.PropertyValue;
import com.sun.star.comp.helper.Bootstrap;
import com.sun.star.frame.XComponentLoader;
import com.sun.star.lang.XComponent;
import com.sun.star.lang.XMultiComponentFactory;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.uno.XComponentContext;

That I can point to in  Eclipse...

I did find some apache open office .jar files and that mostly fixed most of the problems with these, but that is not LibreOffice.... can some one provide a path or download where I can obtain these?
Comment 10 Mike Little 2022-11-10 10:48:53 UTC
Notes.. and an update... 
1.	Used Eclipse as the IDE. 
2.	Set up the build path external class paths [external JARs] as:
a.	Applications/LibreOffice.app/Contents/Resources/java/libreoffice.jar;
b.	/Applications/LibreOffice.app/Contents/Resources/java/unoloader.jar;
3.	Got a warning message …

“warning: com.sun.star.lib.util.NativeLibraryLoader must be loaded by com.sun.star.lib.unoloader.UnoClassLoader for java_uno bridge to work (not a problem if this is using Java remote bridge or unit test)”
com.sun.star.comp.helper.BootstrapException: no office executable found!

Added ‘import com.sun.star.lib.util.NativeLibraryLoader;” 

But does not appear to being used

4.	I need to provide the path to the application, added the following to the class path in Eclipse… 

/Applications/LibreOffice.app/Contents/MacOS/

5.	Application starts and loads the LibreOffice canvas, but then freezes, no UI elements loaded... I will check this through the Eclipse debugger. Still working on it…
Comment 11 Sierk Bornemann 2022-11-10 13:30:11 UTC
(In reply to Simon Muschel from comment #4)
> Thank you for your reply - sorry my description was not precise enough.
> 
> Prerequisites for test case:
> * M1 Mac (e.g. MacBook Pro)
> * Java JDK installation (I used version 17)
> 
> 
> Assumptions for the following steps:
> * LibreOffice is installed in the standard location
> (/Applications/LibreOffice.app)
> * Java is installed an can be executed from Terminal
> 
> 
> Steps to reproduce behavior:
> * Download attachment, rename file to Test.java
> * Open Terminal, go to folder containing Test.java
> * execute command to compile test case (all in one line):
> 
> javac -cp
> /Applications/LibreOffice.app/Contents/Resources/java/libreoffice.jar
> Test.java
> 
> * Execution of previous step should result in creation of file Test.class
> * execute command to run test case (all in one line):
> 
> java -classpath
> /Applications/LibreOffice.app/Contents/MacOS/:/Applications/LibreOffice.app/
> Contents/Resources/java/libreoffice.jar:/Applications/LibreOffice.app/
> Contents/Resources/java/unoloader.jar:.
> -Djava.library.path=/Applications/LibreOffice.app/Contents/Frameworks Test
> 
> 
> Result:
> LibreOffice window opens, but no Writer document is started. LO window stays
> grayed out. Process has to be terminated.
> 
> Expected Result:
> LO window opens, a new Writer document is started. After 15 seconds, Writer
> document/window will be closed. Test case exits.


I can confirm the issue in question, and I can confirm the result (I did as described above to reproduce the issue).



LibreOffice:
------------
Version: 7.4.3.1 / LibreOffice Community
Build ID: 3793858a34d8fef5b92f8fee233f97766f05e281
CPU threads: 10; OS: Mac OS X 13.0.1; UI render: default; VCL: osx
Locale: de-DE (de_DE.UTF-8); UI: de-DE
Calc: threaded

Hardware:
---------
% /usr/sbin/system_profiler SPHardwareDataType | grep "Model Name"
      Model Name: MacBook Pro
% /usr/sbin/system_profiler SPHardwareDataType | grep "Model Identifier"
      Model Identifier: MacBookPro18,3
% /usr/sbin/system_profiler SPHardwareDataType | grep "Chip"            
      Chip: Apple M1 Pro

OS:
---
% uname -a
Darwin xyz.local 22.1.0 Darwin Kernel Version 22.1.0: Sun Oct  9 20:15:09 PDT 2022; root:xnu-8792.41.9~2/RELEASE_ARM64_T6000 arm64

% uname -m
arm64

% machine                                                                                  
arm64e

% sw_vers                
ProductName:		macOS
ProductVersion:		13.0.1
BuildVersion:		22A400

Java JDK:
---------
% java --version
java 19.0.1 2022-10-18
Java(TM) SE Runtime Environment (build 19.0.1+10-21)
Java HotSpot(TM) 64-Bit Server VM (build 19.0.1+10-21, mixed mode, sharing)

% /usr/libexec/java_home
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home

resp.

% JAVA_HOME=$(/usr/libexec/java_home); echo $JAVA_HOME
/Library/Java/JavaVirtualMachines/jdk-19.jdk/Contents/Home