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

java.lang.NoClassDefFoundError: org.json.JSONString #388

Closed
ITWall opened this issue Aug 15, 2018 · 10 comments
Closed

java.lang.NoClassDefFoundError: org.json.JSONString #388

ITWall opened this issue Aug 15, 2018 · 10 comments
Milestone

Comments

@ITWall
Copy link

ITWall commented Aug 15, 2018

When I use 0.10.4 version, I got this error when I do the sample in readme. I don't know why but after add this library http://mvnrepository.com/artifact/org.json/json, I solved it. Not so sure if this is a bug or not.

@lhazlewood
Copy link
Contributor

Sigh. Android is killing me! 😭

org.json.JSONString and org.json.JSONWriter are used by the implementation but never used by Android at runtime. When the class is loaded, that's when it barfs. I'll have to change the implementation again, potentially duplicating logic from later org.json releases that Android doesn't have.

Thanks for reporting this. You're correct - the workaround in the meantime is to include the org.json .jar.

@lhazlewood lhazlewood added this to the 0.10.5 milestone Aug 15, 2018
lhazlewood added a commit that referenced this issue Aug 15, 2018
@rodmaz
Copy link

rodmaz commented Aug 15, 2018

Same problem here on Android. Has this been fixed on 0.10.5?
When we include version 0.10.5 we get Gradle sync failed on Gradle/Android Studio.

@rodmaz
Copy link

rodmaz commented Aug 15, 2018

This was causing the reported "freeze" when we called the compact() method on Android.

@lhazlewood
Copy link
Contributor

lhazlewood commented Aug 15, 2018

0.10.5 is being released as we speak. Maven Central staging is super slow due to degraded network performance, so please allow it 30 minutes or so before trying.

@rodmaz
Copy link

rodmaz commented Aug 15, 2018

Thanks. We tried it like 1h ago as the tag was already there. We will resume tomorrow. Thanks again @lhazlewood!

@fernando-jascovich
Copy link

Hi, I think that this issue (or some new form of it) is still around; when I set dependencies as explained in documentation:

    runtimeOnly('io.jsonwebtoken:jjwt-orgjson:0.10.5') {
        exclude group: 'org.json', module: 'json' //provided by Android natively
    }

And then, I use the following example code:

        val token = Jwts.builder()
                .claim("myclaim", "myclaimValue")
                .signWith(SignatureAlgorithm.HS256, acceptableKey.toByteArray())
                .compact()

I get the following NPE:

java.lang.IllegalStateException: Unable to serialize header to json.
	at io.jsonwebtoken.impl.DefaultJwtBuilder.base64UrlEncode(DefaultJwtBuilder.java:381)
	at io.jsonwebtoken.impl.DefaultJwtBuilder.compact(DefaultJwtBuilder.java:333)
...
Caused by: io.jsonwebtoken.io.SerializationException: Unable to serialize object of type io.jsonwebtoken.impl.DefaultJwsHeader to JSON: null
	at io.jsonwebtoken.io.OrgJsonSerializer.serialize(OrgJsonSerializer.java:47)
	at io.jsonwebtoken.impl.DefaultJwtBuilder.toJson(DefaultJwtBuilder.java:392)
	at io.jsonwebtoken.impl.DefaultJwtBuilder.base64UrlEncode(DefaultJwtBuilder.java:379)
	... 50 more
Caused by: java.lang.NullPointerException
	at io.jsonwebtoken.io.OrgJsonSerializer.toJSONInstance(OrgJsonSerializer.java:67)
	at io.jsonwebtoken.io.OrgJsonSerializer.serialize(OrgJsonSerializer.java:40)
	... 52 more

And if I include org.json.json at build.gradle (this is, remove exclusion from runtimeOnly declaration), code works as expected. I think that there is some weird Android handling there.

@lhazlewood
Copy link
Contributor

lhazlewood commented Jul 12, 2019

@fernando-jascovich Did you set up proguard exclusions properly for org.json?

We can't re-create this - we'd need a sample project from someone to demonstrate the problem.

@fernando-jascovich
Copy link

I'm not using proguard in that project.
I will generate a sample project later so you can check it.

@fernando-jascovich
Copy link

I made this repository for demonstration: https://github.com/fernando-jascovich/jjwt-issue-388
However, it seems to work fine there. So I think my previous crash was due to some interaction with another third party library.

@lhazlewood
Copy link
Contributor

@fernando-jascovich thanks so much for verifying. If you are able to re-create the problem in the future, please do open a new ticket or request to re-open this one. Cheers!

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

4 participants