Skip to content
This repository has been archived by the owner on Jun 20, 2023. It is now read-only.

IllegalAccessError is thrown when Jest tries to access internal deepCopy method com.google.gson.JsonObject class #351

Closed
sarastinishi opened this issue May 4, 2016 · 5 comments
Labels

Comments

@sarastinishi
Copy link

I am using Jest client to work with Elasticsearch from inside Spark application. While it runs as expected when executing Spark in local mode, it fails in cluster mode with the following exception:

Exception in thread "main" java.lang.IllegalAccessError: tried to access method com.google.gson.JsonObject.deepCopy()Lcom/google/gson/JsonObject; from class com.google.gson.GsonUtils
at com.google.gson.GsonUtils.deepCopy(GsonUtils.java:8)
at io.searchbox.core.SearchResult.extractHit(SearchResult.java:114)
at io.searchbox.core.SearchResult.getHits(SearchResult.java:82)
at io.searchbox.core.SearchResult.getHits(SearchResult.java:63)
at io.searchbox.core.SearchResult.getHits(SearchResult.java:59)

There was a commit cdd62a8 made on Dec 26, 2015 that introduced GsonUtils class that simply calls package level deepCopy method of com.google.gson.JsonObject class by simply defining GsonUtils in com.google.gson package. It seems like a not very good practice to access internal methods. It may cause problems when using multiple classloaders (just like with Spark example above).

@kramer
Copy link
Member

kramer commented May 4, 2016

See the discussion that lead me to create that utils class here: google/gson#760

@sarastinishi
Copy link
Author

Do you think it's a good idea to still call non public methods through defining gson package in Jest? Isn't it better to use some other way to clone objects that does not cause any exceptions?

@sarastinishi
Copy link
Author

sarastinishi commented May 4, 2016

Thank you for bringing up this issue @yuriyfilonov!
I would very much rather not have another additional dependency just for this purpose. If you have an alternative approach or solution let's discuss that on #351 but unfortunately I won't be merging this PR.

I am confused. You prefer to allow exceptions to one additional dependency?

@kramer
Copy link
Member

kramer commented May 4, 2016

As you mentioned the issue occurs only under certain environments ("when using multiple classloaders (just like with Spark example above)") which I would guess is not the prominent use case for this library. This decreases the severity of the exception in the big picture. On the other hand you are suggesting to introduce a new dependency which will come with it's own baggage of possible bugs and maintenance needs, which makes it a "load" (or debt if you will) on the whole project.

Considering the above pro/con comparison it makes more sense (at least maintenance-wise) to not take this suggested fix into the project.

And to answer your question, no I don't think the existing utils class is a good solution, it is simply a workaround. I'd be more than happy to replace it with a similarly light weight solution.

@kramer kramer added the bug label May 4, 2016
@sarastinishi
Copy link
Author

Makes sense. I have found another solution to this problem. Please, see pl #353

@kramer kramer closed this as completed in 354db04 May 4, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants