parse-community / ParseUI-Android

ParseUI contains user interface libraries for building apps with the Parse Android SDK.
Other
592 stars 324 forks source link

unwrap() NPE on Twitter Login #122

Closed passy closed 8 years ago

passy commented 8 years ago

I couldn't find any reference to this particular call in the repo so apologies if this is the wrong place to report it.

I'm trying to log in via Twitter, but both the Activity approach[0] or the manual approach[1] lead to the same error: A "Twitter login failed" toast and this in the debug log:

01-18 20:19:01.682 2636-2636/? W/ParseLoginFragment: Twitter login failed, exception: com.parse.ParseException: com.parse.internal.signpost.exception.OAuthCommunicationException: Communication with the service provider failed: Attempt to invoke interface method 'java.lang.Object com.parse.internal.signpost.http.HttpRequest.unwrap()' on a null object reference

[0] Activity call:

val builder = ParseLoginBuilder(this);
startActivityForResult(builder.build(), 0);

[1] Manual:

ParseTwitterUtils.logIn(this, LogInCallback { parseUser, parseException -> ... })

[2] Application setup:

override fun onCreate() {
    super.onCreate()

    Parse.enableLocalDatastore(this)
    Parse.setLogLevel(Parse.LOG_LEVEL_DEBUG)
    Parse.initialize(this, BuildConfig.PARSE_APPLICATION_ID, BuildConfig.PARSE_CLIENT_KEY)
    ParseTwitterUtils.initialize(BuildConfig.TWITTER_CONSUMER_KEY, BuildConfig.TWITTER_CONSUMER_SECRET)
}

Is there any part of the setup I'm missing?

passy commented 8 years ago

The actual error happened way upstream and was unfortunately swallowed by downstream exception handling and not correctly re-raised. The issue was that some other dependencies bumped okhttp to >= 1.6 which doesn't include com.squareup.okhttp.OkUrlFactory. This snippet here in com.parse.internal.signpost.basic.HttpURLConnectionClient failed silently:

    public static HttpURLConnectionClient create() {
        try {
            final Class okHttpClientClass = Class.forName("com.squareup.okhttp.OkHttpClient");
            final Object okHttpClient = okHttpClientClass.getConstructor().newInstance();
            final Class okUrlFactoryClass = Class.forName("com.squareup.okhttp.OkUrlFactory");
            final Object okUrlFactory = okUrlFactoryClass.getConstructor(okHttpClientClass).newInstance(okHttpClient);
            final Method okUrlFactoryOpen = okUrlFactoryClass.getMethod("open", URL.class);
            return new HttpURLConnectionClient(true, okUrlFactory, okUrlFactoryOpen);
        } catch (Exception e) {
            return new HttpURLConnectionClient(true, null, null);
        }
    }

And when com.parse.internal.signpost.basic.HttpURLConnectionClient#open is called, it raises an NPE. It'd be fantastic if this could at least write to the log informing you about the failed reflection call.

The actual fix was adding this for me:

compile 'com.squareup.okhttp:okhttp-urlconnection:2.7.2'