sarweshkumar47/Curve-Fit

Random NPE

Closed this issue · 12 comments

ryust commented

Periodically, I'll get a NullPointerException when closing a map with a curve and then reopening it to show the curve again. I haven't isolated a pattern yet. Here is the stack trace:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.makesense.labs.curvefit.interfaces.UiThreadCallback.publishToUiThread(android.os.Message)' on a null object reference
at com.makesense.labs.curvefit.impl.WorkerHandlerThread$1.handleMessage(WorkerHandlerThread.java:83)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)

Periodically, I'll get a NullPointerException when closing a map with a curve and then reopening it to show the curve again. I haven't isolated a pattern yet. Here is the stack trace:

java.lang.NullPointerException: Attempt to invoke interface method 'void com.makesense.labs.curvefit.interfaces.UiThreadCallback.publishToUiThread(android.os.Message)' on a null object reference
at com.makesense.labs.curvefit.impl.WorkerHandlerThread$1.handleMessage(WorkerHandlerThread.java:83)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:164)
at android.os.HandlerThread.run(HandlerThread.java:65)

I'm trying to reproduce the issue. In WorkerHandlerThread class, I have used a WeakReference object to hold a callback reference to the CurveManager class. Therefore, it is eligible for garbage collection. This could be causing some issue, but I'm still not sure. If you could provide me little more details like, steps to reproduce the issue or sending some dummy apk would be helpful to understand the problem better.

ryust commented

I'll look into it some more, but so far no pattern other than opening/closing map with curves. I set the CurveManager to null on map close so something with the weak reference could be the issue. I'm trying to delay showing the curves after map loaded to see if that fixes it.

ryust commented

I'm still getting periodic bug reports with this NPE. Any possibility of wrapping the code with a try/catch so the error doesn't cause a crash?

It's so random I can't offer any more information and the app is so large there is no way to provide you with a test case.

Hi,
I am unable to reproduce the issue of what you are facing right now. By this weekend, I'll release a new beta version of the library which will be compatible with Maps 3.0 beta. Please wait for that release.

Sorry for the delay.

This bug has been fixed in new 2.0.0 beta version. Please try using that.

ryust commented

I can't implement the Android Maps beta yet... any way you can add the fix to the current 1.1.0 release for those of us that need to run without the beta?

ryust commented

If you can tell me what was changed, I'll try to fix it myself on the non-beta version... it's frustrating to have NPEs in a production app for a nice library like this.

Sorry for late reply. I was on leave due to medical emergency. I will add the fix to the non beta version soon.

The patch is applied. Curve-Fit 1.1.1 is available now.

ryust commented

Well, 1.1.1 is actually worse. Not getting NPE, but also 95% of the time the curves do not render on the map. When it rarely renders, then multiple close/open of the map doesn't seem to ever show curves again until the app is restarted.

Is CurveManager.unregister necessary? I haven't been using it.

ryust commented

I think I have it working now. I made sure the unregister was done after the map closed and that may have fixed the issue I had with curves not showing. Thanks for the fix and nice library!

Calling unregister method at the end is necessary. Otherwise, memory leaks will occur for sure. Also, the old GoogleMap object will not be garbage collected and the Handler uses this reference (old) to draw the PolyLine (which will not have any effect).