Bug Hunting Session
Bug 117331 - Remove Split Package for Java 9 compatibility
Summary: Remove Split Package for Java 9 compatibility
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
(earliest affected) release
Hardware: All All
: medium normal
Assignee: Not Assigned
Depends on:
Blocks: Java-Runtime-JRE
  Show dependency treegraph
Reported: 2018-04-29 13:52 UTC by Florian Beetz
Modified: 2019-10-23 09:06 UTC (History)
7 users (show)

See Also:
Crash report or crash signature:


Note You need to log in before you can comment on or make changes to this bug.
Description Florian Beetz 2018-04-29 13:52:05 UTC
The Java libraries ridl, unoil, juh, and jurt all export the package 'com.sun.star'.
This makes them incompatible with the Java 9 module system.

Steps to Reproduce:
1. Add at least two libraries to the module path.
2. Compile.

Actual Results:  
Compilation fails with

error: the unnamed module reads package com.sun.star.security from both unoil and ridl
error: the unnamed module reads package com.sun.star.task from both unoil and ridl
error: the unnamed module reads package com.sun.star.util from both unoil and ridl
error: the unnamed module reads package com.sun.star.script from both unoil and ridl
error: the unnamed module reads package com.sun.star.uno from both jurt and ridl

Expected Results:
Compilation completes without errors.

Reproducible: Always

User Profile Reset: No

Additional Info:

User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36
Comment 1 Xavier Van Wijmeersch 2018-04-30 14:56:48 UTC
openjdk9 is superseded, can you retest it with the 10.0.1 version off openjdk10.

Comment 2 Florian Beetz 2018-04-30 15:16:11 UTC
Thanks for your reply.
Tested again with

openjdk 10.0.1 2018-04-17
OpenJDK Runtime Environment (build 10.0.1+10)
OpenJDK 64-Bit Server VM (build 10.0.1+10, mixed mode)

The problem persists.
Comment 3 Buovjaga 2018-06-07 17:12:52 UTC
Pinged devs on IRC and response was cautiously positive, so I will set this to NEW
Comment 4 Michael Stahl (CIB) 2019-05-02 08:42:31 UTC
how does one reproduce this? clearly it doesn't happen during any of the numerous junit tests that run as part of the LO build.

the SDK's jars don't make any claim to be Java Modules, FWIW, and if it's necessary to rearrange the content to make that possible - and thereby break compatibility - then i don't foresee that happening soon.
Comment 5 Rick Heckadon 2019-06-03 16:46:12 UTC
I'm having the same issue, but it's because I've included JavaFX 11 in my project.  JavaFX 11 uses the new Java Modular system that was released in Java version 9.  This means that when the project is compiled, any non modular libraries (i.e. LibreOffice Java API) are put into the unnamed module, where each jar file is treated as a module.  Since ridl, unoil, juh, and jurt are all separate jar files, they are each treated like their own separate module.  This is usually fine, except each jar shares liked named packages (i.e. ridl and jurt both have a package called com.sun.star.lib.util), which in the Java Modular system are called split packages.  Before the Modular system, this was allowed to work without a hitch, but it's a non-starter with Java 9 on and causes errors that stops the project from compiling.  

I have an example project that creates a JavaFX window with a button in it that would create an the SWriter example doc when clicked, but I'm not sure how to share it with everyone?  The project uses NetBeans 11.0, AdoptOpenJDK 11, and JavaFX 11.  If I can't share the code, you may be able to setup the project yourself by merging the JavaFX 12 helloworld example and the SWriter example.  HelloWorld is here: https://github.com/openjfx/samples.  And the Swriter example is here: https://api.libreoffice.org/examples/examples.html#Java_examples.

I think that the best way to solve this issue and still be compatible with older Java versions (Java 8), is to put ridl, unoil, juh, and jurt into a single jar file for Java 9 projects and above, but still have the 4 separate jars for Java 8 projects and below.  By doing this, the Modular system would treat the single jar file as a single module.  The modular system would then not flag this module as having split packages and the project could compile correctly.
Comment 6 Noel Grandin 2019-06-03 18:32:57 UTC
@Rick, so merge the jars yourself and try it out?  They're just zip files, it's really easy to do.
Comment 7 Stephan Bergmann 2019-06-04 06:31:11 UTC
(In reply to Noel Grandin from comment #6)
> @Rick, so merge the jars yourself and try it out?  They're just zip files,
> it's really easy to do.

...though you need to take care to include a proper combined meta-inf/manifest.mf
Comment 8 Rick Heckadon 2019-06-13 21:25:36 UTC
Sorry that this took so long, but I was finally able to merge all the required jars into one jar, included it into the program, and the program finally compiled and worked!  I believe this is the solution to this problem.  Would a merged jar be possible in future updates of LibreOffice?