title: Out-of-nowhere ClassCastException in android
body: <p>This morning I woke up on this strange exception:</p>
  
  <blockquote>
    <p>java.lang.ClassCastException:
    org.apache.harmony.luni.lang.reflect.ImplForVariable cannot be cast to
    java.lang.Class</p>
  </blockquote>
  
  <p>It happens when I try to get a Type argument Class.</p>
  
  <p>Example:</p>
  
  <pre><code>public static Class getTypeParameterClass(Object o, int index) {
      return (Class)
              ((ParameterizedType)o.getClass()
                      .getGenericSuperclass())
                      .getActualTypeArguments()[index];
  }
  </code></pre>
  
  <p>As you can see, this method gets one of the type parameter for a given object's class.</p>
  
  <p>It's been working for months now but today, it stopped.</p>
  
  <p>Usage example:</p>
  
  <pre><code>Collection&lt;Object&gt; foo = new ArrayList&lt;Object&gt;();
  
  Class&lt;?&gt; fooClass = Utils.getTypeParameterClass(foo, 0);
  </code></pre>
  
  <p>And it crashes.</p>
  
  <p>Is there a curse on me for blaming java too many times;) ?</p>
  
  <p>Thanks !</p>