title: IndexOutOfBoundsException in TabLayout in android support design lib
body: <p>I use <a href="http://developer.android.com/tools/support-library/features.html#design" rel="nofollow">android.support.design</a> in all my projects, and today I updated it to latest version </p>
  
  <p>com.android.support:design:22.2.1</p>
  
  <p>It was a bad idea, because my project crashed with </p>
  
  <pre><code>java.lang.IndexOutOfBoundsException: Invalid index 0, size is 0
  java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
  java.util.ArrayList.get(ArrayList.java:308)
  android.support.design.widget.TabLayout.getTabAt(TabLayout.java:407)
  android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:585)
  </code></pre>
  
  <p>After some debugging, I found a problem in this method:</p>
  
  <pre><code> public void setupWithViewPager(@NonNull ViewPager viewPager) {
      PagerAdapter adapter = viewPager.getAdapter();
      if(adapter == null) {
          throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
      } else {
          this.setTabsFromPagerAdapter(adapter);
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(this));
          this.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
          if(this.mSelectedTab == null || this.mSelectedTab.getPosition() != viewPager.getCurrentItem()) {
              this.getTabAt(viewPager.getCurrentItem()).select();// ERROR On my code I'm used empty adapter 
          }
  
      }
  }
  </code></pre>
  
  <p>But in previous version 22.2.0 of lib, all was  working fine:</p>
  
  <pre><code>    public void setupWithViewPager(ViewPager viewPager) {
      PagerAdapter adapter = viewPager.getAdapter();
      if(adapter == null) {
          throw new IllegalArgumentException("ViewPager does not have a PagerAdapter set");
      } else {
          this.setTabsFromPagerAdapter(adapter);
          viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(this));
          this.setOnTabSelectedListener(new TabLayout.ViewPagerOnTabSelectedListener(viewPager));
      }
  }
  </code></pre>
  
  <p>Who did it and who can be punished for it?</p>
  
  <p>Please help me find developers for Android support Design library.</p>