title: How to fix Fatal Exception: java.lang.IndexOutOfBoundsException Index: 0, Size: 1
body: <p>Kotlin program snippet:</p>
  <pre><code>fun peek() = if (!elements.isEmpty() &amp;&amp; elements.size &gt; 0) elements[0] else null
  </code></pre>
  <p>It works great, but sometimes I get a firebase crash report:</p>
  <blockquote>
  <p>Fatal Exception: java.lang.IndexOutOfBoundsException Index: 0, Size: 1
  java.util.ArrayList.get (ArrayList.java:437)
  bigmick.ghu.util.Queue.peek (Queue.kt:17)</p>
  </blockquote>
  <p>For me it sounds crazy: the list's size is 1, also the first (existing) element can be referred by index=0.</p>
  <p>As far as I know it should work. But sometimes it does not.</p>