experiences with prototype

Maurizio Cimadamore maurizio.cimadamore at oracle.com
Tue Feb 3 19:09:32 UTC 2015


On 03/02/15 18:46, Maurizio Cimadamore wrote:
> I will also investigate on the crash you are getting... 
Hi Peter,
the crash is coming from this code in AbstractCollection (see code in bold):

     public boolean contains(Object o) {
         __WhereVal(E) {
             Iterator<E> it = iterator();
             if (o == null) {
                 return false;
             } else {
                 while (it.hasNext())
*if (o.equals((Object) it.next()))*
                         return true;
             }
             return false;
         }
         __WhereRef(E) {
             Iterator<E> it = iterator();
             if (o == null) {
                 while (it.hasNext())
                     if (it.next() == null)
                         return true;
             } else {
                 while (it.hasNext())
                     if (o.equals(it.next()))
                         return true;
             }
             return false;
         }
     }

I believe that, apart from the obvious javac bug, the code has an issue, 
as it.next() is supposed to return a value there, but you are casting to 
Object?

For the records - a simpler test case for the bug is this:

class Foo<any E> {
     E e;
     E get() { return e; }

     void test() {
         __WhereVal(E) {
             Object o = (Object)get();
         }
     }
}

Maurizio


More information about the valhalla-dev mailing list