urbanairship / android-library

Urban Airship Android SDK
Other
112 stars 123 forks source link

NullPointerException: Attempt to invoke virtual method 'com.urbanairship.json.JsonList com.urbanairship.json.JsonValue.optList()' #30

Closed korre closed 7 years ago

korre commented 7 years ago

I'm having trouble with a NPE on app start after updating to 8.9.2 from 8.6.1.

I tried to setup a new clean project but the same error occurs, even when the app only contains an activity and the Urban Airship integration, and I'm having a little trouble figuring out how to solve it.

The crash appears 100% of the time after some seconds when app is started and just idling.

Followed this instructions when setting up project: https://docs.urbanairship.com/platform/android/#configure-a-push-provider

Application.onCreate()

        AirshipConfigOptions uaOptions = new AirshipConfigOptions.Builder()
                .setDevelopmentAppKey(getResources().getString(R.string.ua_dev_key))
                .setDevelopmentAppSecret(getResources().getString(R.string.ua_dev_secret))
                .setProductionAppKey(getResources().getString(R.string.ua_prod_key))
                .setProductionAppSecret(getResources().getString(R.string.ua_prod_secret))
                .setInProduction(!BuildConfig.DEBUG)
                .setProductionLogLevel(Log.ERROR)
                .setDevelopmentLogLevel(Log.VERBOSE)
                .setAllowedTransports(new String[] {AirshipConfigOptions.GCM_TRANSPORT})
                .setGcmSender(getResources().getString(R.string.ua_gcm_sender))
                .setAnalyticsEnabled(true)
                .build();

        UAirship.takeOff(this, uaOptions, new UAirship.OnReadyCallback() {
            @Override
            public void onAirshipReady(UAirship airship) {
                airship.getPushManager().setChannelTagRegistrationEnabled(false);
                airship.getPushManager().setNotificationFactory(new NotificationFactory(getApplicationContext()));
                airship.getPushManager().setPushEnabled(true);
                airship.getPushManager().setUserNotificationsEnabled(true);
            }
        });

build.gradle

apply plugin: 'com.android.application'

android {
    compileSdkVersion 26
    buildToolsVersion "26.0.1"
    defaultConfig {
        applicationId "se.kmdev.gcmtest"
        minSdkVersion 16
        targetSdkVersion 26
        versionCode 1
        versionName "1.0"
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    ext {
        support = '26.1.0'
        gms = '11.4.0'
    }
    compile fileTree(dir: 'libs', include: ['*.jar'])
    androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
        exclude group: 'com.android.support', module: 'support-annotations'
    })

    compile "com.google.android.gms:play-services-analytics:$gms"

    compile "com.android.support:appcompat-v7:$support"
    compile "com.android.support:support-v4:$support"
    compile "com.android.support:cardview-v7:$support"
    compile "com.android.support:support-annotations:$support"
    compile 'com.android.support.constraint:constraint-layout:1.0.2'
    compile "com.urbanairship.android:urbanairship-sdk:8.9.2"

    testCompile 'junit:junit:4.12'
}

Stacktrace:

FATAL EXCEPTION: pool-11-thread-1
                                                                Process: se.kmdev.gcmtest, PID: 6381
                                                                java.lang.NullPointerException: Attempt to invoke virtual method 'com.urbanairship.json.JsonList com.urbanairship.json.JsonValue.optList()' on a null object reference
                                                                    at com.urbanairship.push.ChannelRegistrationPayload.parseJson(ChannelRegistrationPayload.java:353)
                                                                    at com.urbanairship.push.PushManagerJobHandler.getLastRegistrationPayload(PushManagerJobHandler.java:417)
                                                                    at com.urbanairship.push.PushManagerJobHandler.shouldUpdateRegistration(PushManagerJobHandler.java:358)
                                                                    at com.urbanairship.push.PushManagerJobHandler.updateChannel(PushManagerJobHandler.java:226)
                                                                    at com.urbanairship.push.PushManagerJobHandler.onUpdateChannelRegistration(PushManagerJobHandler.java:211)
                                                                    at com.urbanairship.push.PushManagerJobHandler.performJob(PushManagerJobHandler.java:121)
                                                                    at com.urbanairship.push.PushManager.onPerformJob(PushManager.java:386)
                                                                    at com.urbanairship.job.Job$1.run(Job.java:83)
                                                                    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
                                                                    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
                                                                    at java.lang.Thread.run(Thread.java:764)
korre commented 7 years ago

Tried to put the configuration in airshipconfig.properties instead but same problem occurs.

rlepinski commented 7 years ago

@korre Its a regression we introduced in 8.9.1. We will have a patch today.

rlepinski commented 7 years ago

Released in 8.9.3. Here is the fix: https://github.com/urbanairship/android-library/commit/b32ab5e860e509c6096ee353d3a2f789945069cb