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

Failure to simultaneously resolve two consumers using each of v2.10.1 and v2.11.0 together in Eclipse IDE #2725

Closed
scottkurz opened this issue Aug 8, 2024 · 6 comments · Fixed by #2735
Labels

Comments

@scottkurz
Copy link

scottkurz commented Aug 8, 2024

Gson version

v2.10.1 and v2.11.0, together in an OSGi runtime

Java / Android version

Java 21

Used tools

Eclipse IDE 2024-06 release, "Enterprise Java" package

Description

As described in eclipse-jdtls/eclipse.jdt.ls#3236 (comment)

I'm trying to load two versions of the same bundle, one which uses gson v2.10.1 and the other using gson v2.11.0.

In more detail, first, there is lsp4j v0.22.0 with
Import-Package: com.google.gson;version="[2.9.1,2.11)",com.google.gson.a nnotations;version="[2.9.1,2.11)",

(shown here as part of a bigger excerpt of the bundle MF):

Bundle-SymbolicName: org.eclipse.lsp4j
...
Export-Package: org.eclipse.lsp4j;uses:="com.google.gson.annotations,org
 .eclipse.lsp4j.adapters,org.eclipse.lsp4j.jsonrpc.messages,org.eclipse.
 lsp4j.jsonrpc.validation";version="0.22.0",org.eclipse.lsp4j.adapters;u
 ses:="com.google.gson,com.google.gson.reflect,com.google.gson.stream,or
 g.eclipse.lsp4j,org.eclipse.lsp4j.jsonrpc.messages";version="0.22.0",or
 g.eclipse.lsp4j.launch;uses:="org.eclipse.lsp4j.jsonrpc,org.eclipse.lsp
 4j.services";version="0.22.0",org.eclipse.lsp4j.services;uses:="org.ecl
 ipse.lsp4j,org.eclipse.lsp4j.adapters,org.eclipse.lsp4j.jsonrpc.json,or
 g.eclipse.lsp4j.jsonrpc.messages,org.eclipse.lsp4j.jsonrpc.services";ve
 rsion="0.22.0",org.eclipse.lsp4j.util;uses:="org.eclipse.lsp4j";version
 ="0.22.0"
Import-Package: com.google.gson;version="[2.9.1,2.11)",com.google.gson.a
 nnotations;version="[2.9.1,2.11)",com.google.gson.reflect;version="[2.9
 .1,2.11)",com.google.gson.stream;version="[2.9.1,2.11)",java.io,java.la
 ng,java.lang.invoke,java.lang.reflect,java.util,java.util.concurrent,ja
 va.util.function,org.eclipse.lsp4j,org.eclipse.lsp4j.adapters,org.eclip
 se.lsp4j.jsonrpc;version="[0.22,1)",org.eclipse.lsp4j.jsonrpc.json;vers
 ion="[0.22,1)",org.eclipse.lsp4j.jsonrpc.json.adapters;version="[0.22,1
 )",org.eclipse.lsp4j.jsonrpc.messages;version="[0.22,1)",org.eclipse.ls
 p4j.jsonrpc.services;version="[0.22,1)",org.eclipse.lsp4j.jsonrpc.util;
 version="[0.22,1)",org.eclipse.lsp4j.jsonrpc.validation;version="[0.22,
 1)",org.eclipse.lsp4j.services

Next, there is lsp4j v0.23.1 with
Import-Package: com.google.gson;version="[2.9.1,3.0)",com.google.gson.an notations;version="[2.9.1,3.0)"

(Bigger bundle MF excerpt here:)

Export-Package: org.eclipse.lsp4j;uses:="com.google.gson.annotations,org
 .eclipse.lsp4j.adapters,org.eclipse.lsp4j.jsonrpc.messages,org.eclipse.
 lsp4j.jsonrpc.validation";version="0.23.1",org.eclipse.lsp4j.adapters;u
 ses:="com.google.gson,com.google.gson.reflect,com.google.gson.stream,or
 g.eclipse.lsp4j,org.eclipse.lsp4j.jsonrpc.messages";version="0.23.1",or
 g.eclipse.lsp4j.launch;uses:="org.eclipse.lsp4j.jsonrpc,org.eclipse.lsp
 4j.services";version="0.23.1",org.eclipse.lsp4j.services;uses:="org.ecl
 ipse.lsp4j,org.eclipse.lsp4j.adapters,org.eclipse.lsp4j.jsonrpc.json,or
 g.eclipse.lsp4j.jsonrpc.messages,org.eclipse.lsp4j.jsonrpc.services";ve
 rsion="0.23.1",org.eclipse.lsp4j.util;uses:="org.eclipse.lsp4j";version
 ="0.23.1"
Import-Package: com.google.gson;version="[2.9.1,3.0)",com.google.gson.an
 notations;version="[2.9.1,3.0)",com.google.gson.reflect;version="[2.9.1
 ,3.0)",com.google.gson.stream;version="[2.9.1,3.0)",java.io,java.lang,j
 ava.lang.invoke,java.lang.reflect,java.util,java.util.concurrent,java.u
 til.function,org.eclipse.lsp4j,org.eclipse.lsp4j.adapters,org.eclipse.l
 sp4j.jsonrpc;version="[0.23,1)",org.eclipse.lsp4j.jsonrpc.json;version=
 "[0.23,1)",org.eclipse.lsp4j.jsonrpc.json.adapters;version="[0.23,1)",o
 rg.eclipse.lsp4j.jsonrpc.messages;version="[0.23,1)",org.eclipse.lsp4j.
 jsonrpc.services;version="[0.23,1)",org.eclipse.lsp4j.jsonrpc.util;vers
 ion="[0.23,1)",org.eclipse.lsp4j.jsonrpc.validation;version="[0.23,1)",
 org.eclipse.lsp4j.services

Though I have gson v2.10.1 and 2.11.0 installed I can't resolve both versions of lsp4j. The OSGi console in Eclipse shows:

g! lb com.google.gson

   15|Resolved   |    4|Gson (2.11.0)|2.11.0
 1011|Resolved   |    4|Gson (2.10.1)|2.10.1

g! lb org.eclipse.lsp4j
 
  621|Resolved   |    4|org.eclipse.lsp4j (0.23.1.v20240521-1815)|0.23.1.v20240521-1815
 1024|Installed  |    4|org.eclipse.lsp4j (0.22.0.v20240213-2011)|0.22.0.v20240213-2011

g! diag 1024
org.eclipse.lsp4j [1024]
  Unresolved requirement: Import-Package: com.google.gson.annotations; version="[2.9.1,2.11.0)"

As noted in this issue response, the problem seems likely related to the way in which the com.google.gson imports com.google.gson.annotations without any qualifications on the version.

Reproduction steps

Besides the original recreate, a simpler method would be:

  1. Install 2024-06 Eclipse, using the Enterprise Java package (this has both the org.eclipse.tips.json v0.3.400 plugin using gson v2.11.0 and it also has the OSGi console, for convenience).
  2. Install https://download.eclipse.org/lsp4j/updates/releases/0.22.0
    Help -> Install New Software then click Add button.
    For Location field add https://download.eclipse.org/lsp4j/updates/releases/0.22.0 then click Add.
  3. Check the "Lsp4j" check box, and complete the install, and restart.
  4. Open OSGi console:
    Window->Show View->Console, select "Host OSGi Console" from drop-down
  5. From console prompt type:
    lb org.eclipse.lsp4j
    You'll see something like:
  621|Resolved   |    4|org.eclipse.lsp4j (0.23.1.v20240521-1815)|0.23.1.v20240521-1815
 ...
 1013|Installed  |    4|org.eclipse.lsp4j (0.22.0.v20240213-2011)|0.22.0.v20240213-2011
  1. Type: diag 1013 (or whatever bundle # you see in the prev. cmd):
    You'll see something like:
org.eclipse.lsp4j [1013]
  Unresolved requirement: Import-Package: com.google.gson.annotations; version="[2.9.1,2.11.0)"
@scottkurz scottkurz added the bug label Aug 8, 2024
@scottkurz scottkurz changed the title Hard to use v2.10.1 and v2.11.0 together in Eclipse IDE Failure to simultaneously resolve both v2.10.1 and v2.11.0 together in Eclipse IDE Aug 8, 2024
@scottkurz scottkurz changed the title Failure to simultaneously resolve both v2.10.1 and v2.11.0 together in Eclipse IDE Failure to simultaneously resolve two consumers using each of v2.10.1 and v2.11.0 together in Eclipse IDE Aug 8, 2024
@Marcono1234
Copy link
Collaborator

Marcono1234 commented Aug 9, 2024

(Disclaimer: I am not very familiar with OSGi)

Maybe related to #1001

Gson does not explicitly define Import-Package: com.google.gson.annotations in its MANIFEST.MF; instead it defines Import-Package: * (and manually sets sun.misc as optional). This way bnd-maven-plugin determines the imported packages.
The concept of both exporting and importing the same package seems intentional and is probably done to enable substitution (OSGi Core 8 §3.6.6).

I guess we could remove these self imports by writing something like:

Import-Package: sun.misc;resolution:=optional, !com.google.gson, !com.google.gson.*, *

But I am not sure if omitting the import could have any negative side effect. Or if alternatively it is possible to specify the version for the import, and if that has any negative side effect.

Maybe we should raise this issue at https://github.com/bndtools/bnd?
Edit: Have created bndtools/bnd#6220 now.

@scottkurz
Copy link
Author

scottkurz commented Aug 13, 2024

Or if alternatively it is possible to specify the version for the import, and if that has any negative side effect.

This was the suggestion in the comment from @rgrunber in: eclipse-jdtls/eclipse.jdt.ls#3236 (comment) noting another packaging of this bundle: https://git.eclipse.org/r/plugins/gitiles/orbit/orbit-recipes/+/refs/heads/master/google/com.google.gson_2.10.1/osgi.bnd
using

Import-Package: \
  | com.google.gson.*;version="${range;[==,+);${package-version}}", \
  | *;resolution:=optional

I'm not too familiar with either the history or the bnd syntax here, nor the ramifications really, just making the connection there in noting that.

@rgrunber
Copy link

rgrunber commented Aug 13, 2024

The self import is fine to keep as long as the range is tight enough so as to never include a package from another version of that library. The current self-import is unbounded. You could probably make the range even tighter with ${range;[==,=+) (so instead of the proposed [2.10.0, 3) it will be [2.10.0, 2.11.0).

@Marcono1234
Copy link
Collaborator

I have created bndtools/bnd#6220 to clarify if bnd-maven-plugin should generate these version ranges on its own by default (and to clarify what they think the correct behavior should be). But while trying to change this locally for Gson I noticed some rather strange behavior of the plugin, bndtools/bnd#6221. It seems the range macro is not expanded in all cases; not sure if there is a way to work around this. Otherwise it might be necessary to wait until that is fixed.

@rgrunber
Copy link

Some older discussion on the situation : https://bugs.eclipse.org/bugs/show_bug.cgi?id=183595 .

@chrisrueger
Copy link
Contributor

chrisrueger commented Sep 3, 2024

In bndtools/bnd#6220 (comment) it was proposed to add -noimport:=true to all Exports which should not be imported. This would remove the self-imports in Import-Package instruction.

e.g. in the bnd section of gson's pom.xml

Import-Package: sun.misc;resolution:=optional, *

-exportcontents:\
    com.google.gson.annotations;-noimport:=true

This would result in a MANIFEST.MF where com.google.gson.annotations would NOT appear in the Import-Package list anymore.

Maybe it can even be done for all the gson packages currently exported.

I'll try to create a PR for this.

chrisrueger added a commit to chrisrueger/gson that referenced this issue Sep 3, 2024
based on google#2725 and bndtools/bnd#6220 (comment)
append -noimport:=true to all exports which we do not want to re-import
This avoids issues in OSGi environments where multiple versions of gson are deployed and com.google.gson.annotations causes wiring conflicts between these different versions
eamonnmcmanus pushed a commit that referenced this issue Sep 5, 2024
based on #2725 and bndtools/bnd#6220 (comment)
append -noimport:=true to all exports which we do not want to re-import
This avoids issues in OSGi environments where multiple versions of gson are deployed and com.google.gson.annotations causes wiring conflicts between these different versions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants