Bug 165147 - Scriptforge asks to activate Java (JRE) even if you don’t need it
Summary: Scriptforge asks to activate Java (JRE) even if you don’t need it
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: BASIC (show other bugs)
Version:
(earliest affected)
25.2.0.3 release
Hardware: All All
: medium normal
Assignee: Not Assigned
URL:
Whiteboard: target:25.8.0 target:25.2.2
Keywords:
Depends on:
Blocks: ScriptForge
  Show dependency treegraph
 
Reported: 2025-02-09 15:45 UTC by Uralion
Modified: 2025-02-12 13:42 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Uralion 2025-02-09 15:45:12 UTC
Hi!
I am running this Scriptforge python code:

-*-*-*-*-*-*-*-*-*-*-*-*-*- CODE -*-*-*-*-*-*-*-*-*-*-*-*-*-
from scriptforge import CreateScriptService

def msgbox_last_row(*args):
    bas = CreateScriptService("Basic")
    myDoc = CreateScriptService("Calc", bas.ThisComponent)
    last_row = myDoc.LastRow('Sheet1')
    bas.MsgBox(last_row)
-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-

The case is that, EVERY single time the document is loaded and the script is executed, Libreoffice asks if I want to activate Java (JRE), since it is necessary to run the script (even if using Java is explicitely disabled).
However this is not true, since even if it is not activated and the message is closed, the code runs without problem.

To test it: make sure using a Java (JRE) environment is disabled.

mikekaganski comment here https://ask.libreoffice.org/t/scriptforge-asks-to-activate-java-jre-even-if-you-dont-need-it/117672/8?u=uralion:
'SF has _FindModuleFromMethod function, which calls getChildNodes from macro organizer; and that tries to load Java, because indeed one of its nodes is Java. But the function explicitly only wants Basic.

It seems like they could use ScriptProviderForBasic service 2 instead.'

Thank you very much!!!
Comment 1 Jean-Pierre Ledure 2025-02-11 14:12:34 UTC
I confirm the bug in
Version: 25.2.0.3 (X86_64) / LibreOffice Community
Build ID: e1cf4a87eb02d755bce1a01209907ea5ddc8f069
CPU threads: 6; OS: Linux 6.8; UI render: default; VCL: kf5 (cairo+xcb)
Locale: fr-BE (en_US.UTF-8); UI: en-US
Calc: threaded

1) the given script is written in Python. The same behaviour is observed with next Basic script:
Sub Main
    GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
    myDoc = CreateScriptService("Calc", ThisComponent)
    last_row = myDoc.LastRow('Sheet1')
    MsgBox(last_row)
End Sub

2) The message about the JRE does not appear every time the document is opened but only once per LO session. Whatever the answer to the message (Yes/No/Cancel), the execution of the macro continues and ends normally.

3) I confirm Mike's comments. I am able to get a com.sun.star.comp.scripting.ScriptProviderForBasic service with next code:
Sub XXX
	GlobalScope.BasicLibraries.loadLibrary("ScriptForge")
	GlobalScope.BasicLibraries.loadLibrary("XrayTool")
	factory = getDefaultContext.getValueByName("/singletons/com.sun.star.script.browse.theBrowseNodeFactory")
	Set root = factory.createView(com.sun.star.script.browse.BrowseNodeFactoryViewTypes.MACROORGANIZER)
	a = root.ChildNodes(0)	'	user
	b = a.ChildNodes(0)		'	Basic
	xray b  ' com.sun.star.comp.scripting.ScriptProviderForBasic
End Sub
However this gives the same message about the absence of a JRE.
I do not know a better way. Can someone make a suggestion to have a direct access to that service ?
Comment 2 Mike Kaganski 2025-02-11 14:17:36 UTC
Would 'createUnoService("com.sun.star.comp.scripting.ScriptProviderForBasic")' work?
Comment 3 Jean-Pierre Ledure 2025-02-11 14:26:01 UTC
No, it doesn't work: the service is created but does not contain any subnode.
Comment 4 Mike Kaganski 2025-02-11 14:36:59 UTC
Right, it needs to be initialized. Either

x.initialize(array("user"))

or

x.initialize(array("share"))
Comment 5 Jean-Pierre Ledure 2025-02-11 16:40:21 UTC
Much better.
Thanks.
Comment 6 Commit Notification 2025-02-12 10:48:01 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "master":

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

ScriptForge (SF_Services) fix tdf#165147 do not require JRE

It will be available in 25.8.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 7 Commit Notification 2025-02-12 13:39:24 UTC
Jean-Pierre Ledure committed a patch related to this issue.
It has been pushed to "libreoffice-25-2":

https://git.libreoffice.org/core/commit/6a6c10f25617d492c9db488e31db73c44d687b71

ScriptForge (SF_Services) fix tdf#165147 do not require JRE

It will be available in 25.2.2.

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 8 Uralion 2025-02-12 13:42:20 UTC
Jean-Pierre Ledure and Mike Kaganski (and all others involved if any): I am very grateful for your kindness and efficiency. Thank you very much!