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

IllegalAccessError on version 2.2.0 of plaid-java #103

Closed
dopatraman opened this issue Jan 17, 2018 · 13 comments
Closed

IllegalAccessError on version 2.2.0 of plaid-java #103

dopatraman opened this issue Jan 17, 2018 · 13 comments

Comments

@dopatraman
Copy link

Called the plaidClient.service().itemPublicTokenExchange(request).execute() method and got this error:

java.lang.IllegalAccessError: tried to access method com.google.gson.Gson.newJsonWriter(Ljava/io/Writer;)Lcom/google/gson/stream/JsonWriter; from class retrofit2.converter.gson.GsonRequestBodyConverter

I am on version 2.2.0 of the plaid-java sdk. Please help.

@dopatraman
Copy link
Author

dopatraman commented Jan 17, 2018

Here's an update. I figured an incompatibility with the GSON library may be the source of this. I am using version 2.6.1 of google's gson library

"com.google.code.gson:gson:2.6.1"

It seems that plaid-java has a dependence on version 2.3.1 of gson?

I moved to exclude plaid's version:

plaid : dependencies.create("com.plaid:plaid-java:2.2.0") {
                exclude module: "gson"
            },

This hasn't solved the problem. please help if you can.

@AshokRaj29
Copy link

Update your gson to 2.8.2 and rebuild the project again. That should fix the issue

@AshokRaj29
Copy link

<dependency> <groupId>com.google.code.gson</groupId> <artifactId>gson</artifactId> <version>2.8.2</version> </dependency>

@dopatraman
Copy link
Author

@AshokRaj29 should i exclude plaid's version of gson?

@AshokRaj29
Copy link

No. You should not. Update your gson version to latest. That should solve the issue

@AshokRaj29
Copy link

AshokRaj29 commented Jan 17, 2018

	<dependency>
		<groupId>com.plaid</groupId>
		<artifactId>plaid-java</artifactId>
		<version>2.2.0</version>
	</dependency>

	<dependency>
		<groupId>com.squareup.retrofit2</groupId>
		<artifactId>retrofit</artifactId>
		<version>2.1.0</version>
	</dependency>
	<dependency>
		<groupId>com.squareup.retrofit2</groupId>
		<artifactId>converter-gson</artifactId>
		<version>2.1.0</version>
	</dependency>
	<dependency>
		<groupId>com.squareup.okhttp3</groupId>
		<artifactId>okhttp</artifactId>
		<version>3.6.0</version>
	</dependency>
	<dependency>
		<groupId>com.squareup.okhttp3</groupId>
		<artifactId>logging-interceptor</artifactId>
		<version>3.6.0</version>
	</dependency>
	<dependency>
		<groupId>com.google.code.gson</groupId>
		<artifactId>gson</artifactId>
		<version>2.8.2</version>
	</dependency>

@dopatraman
Copy link
Author

@AshokRaj29 i appreciate the suggestion but unfortunately it did not solve the problem. I am still seeing the same exception.

@dopatraman
Copy link
Author

Just an update: I suspect there may be an issue with the compatibility between retrofit and gson.:

square/pagerduty-incidents#19
https://stackoverflow.com/questions/43220484/java-lang-illegalaccesserror-with-retrofit-2-at-com-google-gson-gson-newjsonwrit

Has anyone else had this experience?

@michaelckelly
Copy link
Contributor

@dopatraman trying to investigate this, can you share more about the exact config you have going to repro this? I want to try to get the test suite to fail in a similar environment.

@dopatraman
Copy link
Author

dopatraman commented Jan 18, 2018

@michaelckelly sure.

java version "1.8.0_102"
Java(TM) SE Runtime Environment (build 1.8.0_102-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.102-b14, mixed mode)
Spring 4.2.3.RELEASE
SpringBoot 1.3.1.RELEASE

Just FYI I'm using gradle v2.10:

plaid                    : "com.plaid:plaid-java:2.2.0",
googleGson               : "com.google.code.gson:gson:2.8.2",
okhttp3       : 'com.squareup.okhttp3:okhttp:3.6.0'

Those three seem to be the most relevant ones. If you need more information just let me know.

@dopatraman
Copy link
Author

Just for context, a similar issue was open before and then closed:
#97

@saurabh67
Copy link

@AshokRaj29 Thank you. Your comments helped me a lot.

@simoleone
Copy link

@dopatraman

This method was exposed here , so any version of gson newer than 2.4 (which was released in October 2015!) should work fine.

The version of converter-gson (2.1.0) in use in plaid-java (2.2.) explicitly depends on version 2.7 of gson. Which you can find here in the retrofit2 parent pom. So your assumption that plaid-java is the reason older version of gson is wrong (and that's why excluding its gson dependency isn't helping either!).

Something else in your project is forcing gradle/maven/etc to resolve gson to a version older than 2.4. Take a look at the output of gradle dependencies and/or mvn dependency:tree to investigate, and see about upgrading those dependencies.

Dependency resolution is a unfortunately very complex topic in the whole Java ecosystem. If you were using maven, your approach of adding gson to your own pom.xml would have (probably) worked and (probably) overrode the transitive dependency since (many recent versions of) maven uses a "nearest-wins" strategy for dependency resolution. However, various versions of gradle use a different strategy (which, at least in recent versions is latest wins, unless something is overriding the behavior of course!), and whichever you've got is still picking the super old version of gson in spite of your attempt to bring in a higher version.

I hope that helps!

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