Repository: wdullaer/MaterialDateTimePicker

Issue #499: Crash in DayPickerView
Created: 2018-06-27T14:12:08Z
When performing unit tests with Robolectric and version 3.6.1, I found a crash in the DayPickerView in the following lines of code.

  
    
      MaterialDateTimePicker/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DayPickerView.java
    
    
         Line 249
      in
      2d21725
    
  
  
    

        
          
           ((LinearLayoutManager) getLayoutManager()).scrollToPositionWithOffset(position, 0); 
        
    
  


It looks like this is because in the following constructor:

  
    
      MaterialDateTimePicker/library/src/main/java/com/wdullaer/materialdatetimepicker/date/DayPickerView.java
    
    
         Line 82
      in
      2d21725
    
  
  
    

        
          
           public DayPickerView(Context context, DatePickerController controller) { 
        
    
  


setController is called prior to init. This leaves open an opportunity for a crash when setController triggers onDateChanged() which manipulates the view prior to it being fully initialized via init(). It looks like the code itself hasn't changed too much since it was last working on 3.4.1 so I'm not sure what the actual change that caused this was.
Stacktrace:

java.lang.NullPointerException
at com.wdullaer.materialdatetimepicker.date.DayPickerView$2.run(DayPickerView.java:249)
at org.robolectric.util.Scheduler.runOrQueueRunnable(Scheduler.java:319)
at org.robolectric.util.Scheduler.postDelayed(Scheduler.java:156)
at org.robolectric.util.Scheduler.post(Scheduler.java:135)
at org.robolectric.shadows.ShadowView.post(ShadowView.java:402)
at android.view.View.post(View.java)
at com.wdullaer.materialdatetimepicker.date.DayPickerView.postSetSelection(DayPickerView.java:245)
at com.wdullaer.materialdatetimepicker.date.DayPickerView.goTo(DayPickerView.java:235)
at com.wdullaer.materialdatetimepicker.date.DayPickerView.onDateChanged(DayPickerView.java:301)
at com.wdullaer.materialdatetimepicker.date.DatePickerDialog.updatePickers(DatePickerDialog.java:1077)
at com.wdullaer.materialdatetimepicker.date.DatePickerDialog.onDayOfMonthSelected(DatePickerDialog.java:1068)

Duplicate issue #522: Crash with mindate
Created: 2018-09-05T14:35:41Z
If we set a minimum date and try a quick moving datepiker, in some cases an arrow may appear, which moves to the previous month from the minimum date.

When you click on this arrow, the application crashes with such an error
java.lang.IllegalArgumentException: Invalid target position at android.support.v7.widget.RecyclerView$SmoothScroller.start(RecyclerView.java:11377) at android.support.v7.widget.RecyclerView$LayoutManager.startSmoothScroll(RecyclerView.java:8090) at android.support.v7.widget.LinearLayoutManager.smoothScrollToPosition(LinearLayoutManager.java:453) at android.support.v7.widget.RecyclerView.smoothScrollToPosition(RecyclerView.java:1700) at com.wdullaer.materialdatetimepicker.date.DayPickerGroup.onClick(DayPickerGroup.java:178) at android.view.View.performClick(View.java:6294) at android.view.View$PerformClick.run(View.java:24774) at android.os.Handler.handleCallback(Handler.java:790) at android.os.Handler.dispatchMessage(Handler.java:99) at android.os.Looper.loop(Looper.java:172) at android.app.ActivityThread.main(ActivityThread.java:6590) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)

Closing comment (2018-09-16T11:37:01Z): I think this issue is similar to #499
I thought I had released the fix for this one already, but that appears not to be the case.
I'll try to get that sorted soon