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

Internal packages are not exported in OSGI jar #2554

Closed
niralepatel opened this issue Nov 24, 2023 · 2 comments
Closed

Internal packages are not exported in OSGI jar #2554

niralepatel opened this issue Nov 24, 2023 · 2 comments
Labels

Comments

@niralepatel
Copy link

Gson version

2.9.1

Java / Android version

Java 1.8

Used tools

Gradle

Description

We were using 2.5 version and now we want to upgrade to 2.9.1 version to resolve security vulnerabilities.
We are using LinkedTreeMap class but now with 2.9.1 versions, LinkedTreeMap is giving compilation issues.
We suspect the reason is, The package com.google.gson.internal is not present under Export-Package section in manifest.mf

2.5:-
Export-Package: com.google.gson;version=2.5, com.google.gson.annotatio
ns;version=2.5, com.google.gson.reflect;version=2.5, com.google.gson.
stream;version=2.5, com.google.gson.internal;version=2.5, com.google.
gson.internal.bind;version=2.5

2.6 onwards
Export-Package: com.google.gson;uses:="com.google.gson.reflect,com.goo
gle.gson.stream";version="2.6.2",com.google.gson.annotations;version=
"2.6.2",com.google.gson.reflect;version="2.6.2",com.google.gson.strea
m;version="2.6.2"

In our manifest, we try to import as below,
Import-Package:
com.google.gson.internal;version="2.9.1"

Please note If we make this as,
com.google.gson;version="2.9.1"

then it works fine, but we suspect at run time it might give ClassNotfound error as this internal package is not exported in gson and not imported at our side.

Expected behavior

It should export internal package same as 2.5 version

Actual behavior

It is not present in Export-package section

Why it was removed, because it was present in 2.5 version? Any reason behind this? Please help me with the questions

@Marcono1234
Copy link
Collaborator

That sounds intentional to me. As the package name suggests LinkedTreeMap is an internal class and part of the Gson implementation details. They are intentionally not publicly exposed (neither in the OSGi metadata nor in module-info.class) so that users don't rely on these classes, and that they can be changed or possibly even be removed depending on Gson's internal usage.

However, why are you using Gson's LinkedTreeMap class in the first place instead of java.util.LinkedHashMap?
It appears the reason why the LinkedTreeMap class was originally added to Gson was to protect against a denial-of-service attack in the JDK class LinkedHashMap (respectively HashMap). But it seems that was resolved in JDK 8, so there might not be any need for LinkedTreeMap anymore, see also #1992 (comment).

@Marcono1234
Copy link
Collaborator

Marcono1234 commented Jul 22, 2024

I am going to close this since it is unlikely that Gson will allow access to internal implementation classes in the future, since that makes maintenance more difficult.

As mentioned above, if you currently rely on an internal class of Gson, please describe your use case. Maybe we can find an alternative for it.

@Marcono1234 Marcono1234 closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants