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

Nullpointer Exception in Token.fromString() #636

Closed
sdoward opened this issue Aug 29, 2018 · 1 comment
Closed

Nullpointer Exception in Token.fromString() #636

sdoward opened this issue Aug 29, 2018 · 1 comment

Comments

@sdoward
Copy link

sdoward commented Aug 29, 2018

The method Token.fromString(@Nullable String) throws a NullPointer when passing a null String into the method. This is missleading for a couple of reasons

  1. The method is annotated with @Nullable so it would seem it acceptable to pass a null object into it. It seems that this annotation should be @NotNull
  2. The stack trace lead me to looking into the internals of JSONTokener which is were the error originates from. Rather than giving a reasonable stacktrace and message so developers can diagnose the issue. A exception could be thrown with a message such "A null string cannot be converted to a token" if a null string is passed into the method.
java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
        at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2673)
        at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2734)
        at android.app.ActivityThread.-wrap12(ActivityThread.java)
        at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1485)
        at android.os.Handler.dispatchMessage(Handler.java:102)
        at android.os.Looper.loop(Looper.java:154)
        at android.app.ActivityThread.main(ActivityThread.java:6195)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:889)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:779)
     Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'int java.lang.String.length()' on a null object reference
        at org.json.JSONTokener.nextCleanInternal(JSONTokener.java:116)
        at org.json.JSONTokener.nextValue(JSONTokener.java:94)
        at org.json.JSONObject.<init>(JSONObject.java:156)
        at org.json.JSONObject.<init>(JSONObject.java:173)
        at com.stripe.android.model.Token.fromString(Token.java:160) ```
@ksun-stripe
Copy link

Hi @sdoward! Thanks so much for bringing this our attention :) Sorry about your time spend debugging. I've put a PR to handle null there the same way the other methods in the class handle null.

#642

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

2 participants