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

[Bug 509535] New: java.lang.NoClassDefFoundError: com/google/gson/annotations/JsonAdapter #44

Closed
mickaelistria opened this issue Jan 10, 2017 · 19 comments
Assignees

Comments

@mickaelistria
Copy link
Contributor

See https://bugs.eclipse.org/bugs/show_bug.cgi?id=509535

@svenefftinge
Copy link
Contributor

@spoenemann could you check is the generated manifest contains proper imports for the mentioned package?

@spoenemann
Copy link
Contributor

The generated manifest does not have an import for com.google.gson.annotations because we don't use it directly. It's used indirectly by Gson. How can the Gson code be denied access to its own classes?

See the top of the stack:

java.lang.NoClassDefFoundError: com/google/gson/annotations/JsonAdapter
	at com.google.gson.internal.bind.JsonAdapterAnnotationTypeAdapterFactory.create(JsonAdapterAnnotationTypeAdapterFactory.java:45)
	at com.google.gson.Gson.getAdapter(Gson.java:423)
	at com.google.gson.Gson.toJson(Gson.java:661)
	at org.eclipse.lsp4j.jsonrpc.json.adapters.MessageTypeAdapterFactory$Adapter.write(MessageTypeAdapterFactory.java:203)
	at org.eclipse.lsp4j.jsonrpc.json.adapters.MessageTypeAdapterFactory$Adapter.write(MessageTypeAdapterFactory.java:54)

@spoenemann
Copy link
Contributor

The Gson code where the exception occurs is this:

rawType.getAnnotation(JsonAdapter.class)

Could it be that Class.getAnnotation(..) throws NoClassDefFoundError because the given annotation type is not found by the classloader of the receiver class?

@svenefftinge
Copy link
Contributor

svenefftinge commented Jan 16, 2017

Ok, so than it seems to be an issue in the manifest of latest gson in orbit.

@spoenemann
Copy link
Contributor

Should we add a package import of com.google.gson.annotations to work around it?

@mickaelistria
Copy link
Contributor Author

Maybe the issue isn't caused by GSon per se, but by having multiple versions of GSon in the OSGi runtime (and maybe different involved bundles loading different version of the class).
cc @mniewrzal : do you get this issue when only gson 2.7 is present or only when 2 versions are avialable?

@mniewrzal
Copy link

Maybe to clarify. Problem is visible ONLY when LSP4E is installed on the top of Oxygen when two version of gson are available:

  • com.google.gson_2.2.4.v201311231704.jar
  • com.google.gson_2.7.0.v20161205-1708.jar

When older version (2.2.4) is removed manually then LSP4E also works ok.

With Neon.2 everything works fine.

@mickaelistria
Copy link
Contributor Author

Ok, so maybe this highlights that gson should be marked as a singleton?

@spoenemann
Copy link
Contributor

The manifest of Gson 2.7 from Orbit says

Import-Package: com.google.gson.annotations

I think this is a bug.

@mickaelistria
Copy link
Contributor Author

I think it is indeed the bug. Either the package should not be imported, or it should be imported with a version constraint.

@dhuebner
Copy link
Contributor

@mickaelistria Than we should report it in gson issue tracker and see what they say.
@spoenemann I hope your workaround will work. If not, try to add uses com.google.gson.annotations directive to the corresponding jsp4j package. That is what helped to get rid of mixed versioned package imports in xbase lib.

@mickaelistria
Copy link
Contributor Author

I opened google/gson#1001 to GSon

@spoenemann
Copy link
Contributor

spoenemann commented Jan 24, 2017

Then we should report it in gson issue tracker and see what they say.

But the manifest is generated by Orbit, not by Gson. It says:

Built-By: genie.orbit

@dhuebner
Copy link
Contributor

But the meta information provided is copied from http://repo1.maven.org/maven2/com/google/code/gson/gson/2.6.2/

@dhuebner
Copy link
Contributor

I just found an issue for 2.8 google/gson#957
:-/

@dhuebner
Copy link
Contributor

@mickaelistria I will provide a patch for orbit gson. I tend to remove the import rather than add a version constraint. It seems to be common to import own packages in BND, but it not really common to do it in equinox.

@dhuebner
Copy link
Contributor

@dhuebner
Copy link
Contributor

Fix will be part of Oxygen M6
Currently available test version:
https://hudson.eclipse.org/orbit/job/orbit-recipes/135/artifact/releng/repository/target/repository/

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

No branches or pull requests

5 participants