n76 / DejaVu

Yet another network location backend for the UnifiedNLP/microG project
GNU General Public License v3.0
100 stars 18 forks source link

NullPointerException - Android 7.1.2 #15

Closed Massedil closed 6 years ago

Massedil commented 6 years ago

02-25 02:25:35.118 E/AndroidRuntime(9342): FATAL EXCEPTION: Thread-133 02-25 02:25:35.118 E/AndroidRuntime(9342): Process: org.fitchfamily.android.dejavu, PID: 9342 02-25 02:25:35.118 E/AndroidRuntime(9342): java.lang.NullPointerException: Attempt to invoke virtual method 'org.fitchfamily.android.dejavu.RfEmitter org.fitchfamily.android.dejavu.Database.getEmitter(org.fitchfamily.android.dejavu.RfIdentification)' on a null object reference 02-25 02:25:35.118 E/AndroidRuntime(9342): at org.fitchfamily.android.dejavu.Cache.get(Cache.java:106) 02-25 02:25:35.118 E/AndroidRuntime(9342): at org.fitchfamily.android.dejavu.BackendService.getRfLocations(BackendService.java:759) 02-25 02:25:35.118 E/AndroidRuntime(9342): at org.fitchfamily.android.dejavu.BackendService.endOfPeriodProcessing(BackendService.java:912) 02-25 02:25:35.118 E/AndroidRuntime(9342): at org.fitchfamily.android.dejavu.BackendService.backgroundProcessing(BackendService.java:727) 02-25 02:25:35.118 E/AndroidRuntime(9342): at org.fitchfamily.android.dejavu.BackendService.access$300(BackendService.java:71) 02-25 02:25:35.118 E/AndroidRuntime(9342): at org.fitchfamily.android.dejavu.BackendService$4.run(BackendService.java:668) 02-25 02:25:35.118 E/AndroidRuntime(9342): at java.lang.Thread.run(Thread.java:761)

n76 commented 6 years ago

Was the back end being started or stopped at the time this exception occurred? The code specifically checks for null values before entering that area, however one of the null checks is not within the synchronized block. So maybe the value changed after the check but before use. . .

Massedil commented 6 years ago

I was using a GPS app (OSMAnd) since some minutes. And I don't have launched UnifiedNlp app.

n76 commented 6 years ago

Not sure if this fix will correct this, but it can't hurt.

ArchangeGabriel commented 6 years ago

I have a similar issue:

03-03 08:20:28.635 E/AndroidRuntime(18427): java.lang.NullPointerException: Attempt to invoke virtual method 'org.fitchfamily.android.dejavu.RfEmitter org.fitchfamily.android.dejavu.Database.getEmitter(org.fitchfamily.android.dejavu.RfIdentification)' on a null object reference
03-03 08:20:28.635 E/AndroidRuntime(18427):     at org.fitchfamily.android.dejavu.Cache.get(Cache.java:106)
03-03 08:20:28.635 E/AndroidRuntime(18427):     at org.fitchfamily.android.dejavu.BackendService.backgroundProcessing(BackendService.java:707)
03-03 08:20:28.635 E/AndroidRuntime(18427):     at org.fitchfamily.android.dejavu.BackendService.access$300(BackendService.java:71)
03-03 08:20:28.635 E/AndroidRuntime(18427):     at org.fitchfamily.android.dejavu.BackendService$4.run(BackendService.java:668)
03-03 08:20:28.635 E/AndroidRuntime(18427):     at java.lang.Thread.run(Thread.java:764)

This log is a bit old but the crash was still occurring recently in the same conditions: just after leaving an PokémonGO. I cannot reproduce it anymore for now because of SafetyNet failing with μG currently, but will try once that last thing is fixed.

n76 commented 6 years ago

@ArchangeGabriel What version of DejaVu are you using? I was pretty sure this particular null pointer error was fixed in the most recent version.

ArchangeGabriel commented 6 years ago

I cannot tell for sure which version that was at that point. Will get a logcat of a recent crash when I get the opportunity.

ale5000-git commented 6 years ago

@n76: I'm not sure but isn't the db == null check needed ony inside rslt == null?

n76 commented 6 years ago

Yes and no. The cache should represent what is in the database, so if we don't have a database we should have nothing in the cache. But technically, you are correct: At that point in the code we really only need to test for db == null if rslt == null. But since we shouldn't be executing the workingset.put() with the RF emitter data unless we have the database opened we should have nothing in the cache always be getting rslt == null if db == null

The interesting part of this is the crash is reported as occurring just after leaving an app that used location services. And the only time we might have a timing error that has us trying to access the cache before the database has been opened is when we are just starting. So why is UnifiedNlp or microG core restarting the backend at that time?

ale5000-git commented 6 years ago

Could you create a debug version that log every start/close/restart action of the backend?