thank you @karolus and @fpy, your help is greatly appreciated!
By the way guys, I have not marked anything as a solution since your help with the code was not related to LibreOffice/Scriptforge asking to enable Java environment. It is also not confirmed to be a bug, so I haven’t marked mikekaganski’s answer as a solution either. In case I am wrong, please let me know.
.
In case you are interested, here is the reported bug
.
EDIT: It has been confirmed as a bug at the report page, so I mark @mikekaganski answer as solution. Thank you very much to all of you!