attach icon indicating copy to clipboard operation
attach copied to clipboard

Push notifications: NPE if google-services.json is not found

Open jperedadnr opened this issue 3 years ago • 2 comments

google-services.json is needed for Android, but if it is not present it causes a NPE:

10-29 12:31:11.799  7338 11290 D GraalCompiled: WARNING: Failed to read google-services.json. Make sure to add the file to the folder: src/android/resources
10-29 12:31:11.799  7338 11290 D GraalCompiled: java.lang.NullPointerException
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at org.glassfish.json.UnicodeDetectingInputStream.fillBuf(UnicodeDetectingInputStream.java:65)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at org.glassfish.json.UnicodeDetectingInputStream.detectEncoding(UnicodeDetectingInputStream.java:104)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at org.glassfish.json.UnicodeDetectingInputStream.<init>(UnicodeDetectingInputStream.java:51)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at org.glassfish.json.JsonParserImpl.<init>(JsonParserImpl.java:71)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at org.glassfish.json.JsonReaderImpl.<init>(JsonReaderImpl.java:49)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at org.glassfish.json.JsonProviderImpl.createReader(JsonProviderImpl.java:112)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at javax.json.Json.createReader(Json.java:201)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at com.gluonhq.attach.pushnotifications.impl.AndroidPushNotificationsService.readGoogleServicesConfiguration(AndroidPushNotificationsService.java:97)
10-29 12:31:11.799  7338 11290 D GraalCompiled: 	at com.gluonhq.attach.pushnotifications.impl.AndroidPushNotificationsService.register(AndroidPushNotificationsService.java:84)

This should be avoided.

jperedadnr avatar Oct 29 '21 07:10 jperedadnr

This exception is already correctly handled. The actual fatal crash happens later on when trying to initialize Firebase in DalvikPushNotificationsService.initializeFirebase():

10-29 12:31:11.799  7338 11292 F com.d: java_vm_ext.cc:577] JNI DETECTED ERROR IN APPLICATION: JNI NewStringUTF called with pending exception java.lang.IllegalArgumentException: ApplicationId must be set.
10-29 12:31:11.799  7338 11292 F com.d: java_vm_ext.cc:577]   at java.lang.String com.google.android.gms.common.internal.Preconditions.checkNotEmpty(java.lang.String, java.lang.Object) ((null):8)
10-29 12:31:11.799  7338 11292 F com.d: java_vm_ext.cc:577]   at com.google.firebase.FirebaseOptions$Builder com.google.firebase.FirebaseOptions$Builder.setApplicationId(java.lang.String) (com.google.firebase:firebase-common@@19.3.0:87)
10-29 12:31:11.799  7338 11292 F com.d: java_vm_ext.cc:577]   at void com.gluonhq.helloandroid.DalvikPushNotificationsService.initializeFirebase(java.lang.String, java.lang.String, java.lang.String, java.lang.String) (DalvikPushNotificationsService.java:93)

tiainen avatar Oct 29 '21 09:10 tiainen

Right, in any case: we should prevent the NPE (by checking that the file exists before calling Json.createReader(), and also prevent the JNI error by not passing an empty configuration to Firebase.

jperedadnr avatar Oct 29 '21 11:10 jperedadnr