Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #1340 by adding missing "provides" in module-info.java #1339

Merged
merged 2 commits into from
Sep 25, 2024

Conversation

sdyura
Copy link
Contributor

@sdyura sdyura commented Sep 24, 2024

(Fixes #1340)

if we have a src/main/resources/META-INF/services/com.fasterxml.jackson.core.JsonFactory
this works in projects that have no module-info.java, but if a project does have module-info.java
then we need to also add the java modules way of provides

this fixes ServiceLoader<JsonFactory> sl = ServiceLoader.load(JsonFactory.class); not working (returning empty)
for projects that have a module-info.java

if we have a src/main/resources/META-INF/services/com.fasterxml.jackson.core.JsonFactory
this works in projects that have no module-info.java, but if a project does have module-info.java
then we need to also add the java modules way of provides
@pjfanning
Copy link
Member

Would it be possible to provide something to test this with? Even a standalone project.

@pjfanning
Copy link
Member

Or even links to docs that describe this issue and/or fix generally.

@sdyura
Copy link
Contributor Author

sdyura commented Sep 24, 2024

to test you can run ServiceLoader<JsonFactory> sl = ServiceLoader.load(JsonFactory.class); in a project, it will work fine (return 1 item) if the project has no module-info.java, but as soon as you add module-info.java to the project, it will break (return 0 items)

here is a simple project that fails when run: https://github.com/user-attachments/files/17117454/arangodb-java-driver-demo.zip

@sdyura
Copy link
Contributor Author

sdyura commented Sep 25, 2024

it is standard java to Always put the ServiceLoader loaded class in BOTH the "META-INF/services" AND module-info.java, you can see in the other jackson module this is the case:

@pjfanning pjfanning mentioned this pull request Sep 25, 2024
@rashtao
Copy link

rashtao commented Sep 25, 2024

Ideally this should be backported also to older branches.

@pjfanning
Copy link
Member

This will likely be merged but can't users who need this today create their own jar that has a module-info.class in like described in #1341. The workaround jar might also need the META-INF/services/com.fasterxml.jackson.core.JsonFactory file.

The same users who think this is needed yesterday could also build their own jackson-core with this amendment in it.

@cowtowncoder
Copy link
Member

I can backport to, say, 2.16 and 2.17 but unlikely to release new patches for pre-2.17.

I assume this has been tested to work? (even if just manually)

@cowtowncoder cowtowncoder changed the title Fixed missing provides Fix #1340 by adding missing "provides" in module-info.java Sep 25, 2024
@cowtowncoder cowtowncoder merged commit 9f3ed66 into FasterXML:2.18 Sep 25, 2024
9 checks passed
@cowtowncoder
Copy link
Member

Backport in 2.16 and 2.17 in case new versions might be released. But the next version that has the fix will be 2.18.0.

@rashtao
Copy link

rashtao commented Sep 26, 2024

Hi @cowtowncoder ,
I have manually checked that the changes work when building from 2.18. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Missing JsonFactory "provides" SPI with JPMS in jackson-core module
4 participants