Bug 49517

Summary: : Java Macro Embedded in document will not run
Product: LibreOffice Reporter: ajvok1
Component: WriterAssignee: Stephan Bergmann <sberg.fun>
Status: RESOLVED FIXED    
Severity: normal CC: ajvok1, sberg.fun
Priority: medium    
Version: 3.5.2 release   
Hardware: Other   
OS: All   
Whiteboard: BSA target:3.7.0 target:3.6.4
Crash report or crash signature: Regression By:
Attachments: Test file is an empty document with an embedd 'HelloWorld' java macro.

Description ajvok1 2012-05-04 20:40:00 UTC
Created attachment 61063 [details]
Test file is an empty document with an embedd 'HelloWorld' java macro.

Running libreoffice 3.5.2.2

Problem description: 
The HelloWorld java macro that runs just fine when invoked from its normal location (under libreoffice/share/Scripts/) but fails with a scripting error if the same macro is embedded in an .odt and run from there. A popup says: 

"A Scripting framework error occurred while running the Java script org.libreoffice.example.java_scripts.HelloWorld.printHW.

Message: org.libreoffice.example.java_scripts.HelloWorld.printHW"

Running this macro in the same .odt in an earlier version (3.4.4) of libreoffice (and an old openoffice) works just fine.

I have to admit that embedding a macro in a document is not something that I can find any documentation on. Although this is something that I have done for several years with OpenOffice and LibreOffice with no problem, perhaps it was an undocumented feature that has been removed?

Steps to reproduce:
1. First test the existing macro:
Open writer.
Tools/Macro/Run Macros/LibreOffice Macros/HelloWorld/org.libreoffice.example.java_scripts.HelloWorld.printHW
The text "Hello World (in Java)" is written into the open document. 
This is as expected.

2. I do not know the 'correct' method for embedding a macro in a document (if there is one), but this works on earlier versions of libre office:
- save an empty .odt
- unzip the .odt
- copy the HelloWorld.jar and parcel-decsriptor.xml from /opt... to the unzipped files Scripts/java/
- make suitable changes to the META-INF/manifest.xml
- zip it back up to the .odt
To save you the bother, a test.odt is attached to this report.

3. Change your libreoffice security options to allow macros to run from a given directory as a 'trusted source'. Save a copy of test.odt there.

4. Open test.odt. 
Tools/Macro/Run Macros/test.odt/HelloWorld/org.libreoffice.example.java_scripts.HelloWorld.printHW
The above error popup is displayed.

Current behavior:
Macro fails to run.

Expected behavior:
Expect the macro to run and write "Hello World (in Java)" into the .odt.
This works in version 3.4.4

Platform (if different from the browser): 
              
Browser: Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:12.0) Gecko/20100101 Firefox/12.0
Also true on Ubuntu 12.04 64 bit with the same result.
Also tried removing Ubuntu libreoffice packages, downloading everything from libreoffice directy and installing those '.deb's. 
All give same error.
Comment 1 ajvok1 2012-10-25 03:16:36 UTC
Still broken in Version 3.6.2.2
Comment 3 Not Assigned 2012-10-26 16:33:26 UTC
Stephan Bergmann committed a patch related to this issue.
It has been pushed to "master":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=7ea7fb009ddcfb0723e88ba0c5778b5fdbe2b553

fdo#49517: Revert "fdo#46102: Load Java scripts with class loaders [...]"



The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.
Comment 4 Stephan Bergmann 2012-10-26 16:38:30 UTC
(In reply to comment #2)
> Maybe related:
> http://cgit.freedesktop.org/libreoffice/core/commit/
> ?id=dd6c4f4db1d62268d73e09ae52d23f760a967dcc

That commit indeed caused this regression and -- as it looks now -- was not necessary after all; see the commit message of <http://cgit.freedesktop.org/libreoffice/core/commit/?id=7ea7fb009ddcfb0723e88ba0c5778b5fdbe2b553> "fdo#49517: Revert 'fdo#46102: Load Java scripts with class loaders [...]'" for details.

Requested a backport of this fix to libreoffice-3-6 towards LO 3.6.4 as <https://gerrit.libreoffice.org/922>.
Comment 5 Not Assigned 2012-10-27 15:41:52 UTC
Stephan Bergmann committed a patch related to this issue.
It has been pushed to "libreoffice-3-6":

http://cgit.freedesktop.org/libreoffice/core/commit/?id=2f42a6cdb63ef8471c1ed54bea3a232272474182&g=libreoffice-3-6

fdo#49517: Revert "fdo#46102: Load Java scripts with class loaders [...]"


It will be available in LibreOffice 3.6.4.

The patch should be included in the daily builds available at
http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
http://wiki.documentfoundation.org/Testing_Daily_Builds
Affected users are encouraged to test the fix and report feedback.