Menu

#27 List.iterator does not return a valid iterator.

v1.0 (example)
closed-fixed
5
2008-12-01
2007-12-04
No

List l = new ArrayList();
l.add("Something");
l.add("Else");
Iterator i = l.iterator();
while (i.hasNext()) {
//
}

Will say that i.hasNext() is not a function. In fact, this seems to be a problem when instantiating an inner class.

AbstractList defines two inner classes, SimpleListIterator and FullListIterator. The method iterator() should return a SimpleListIterator, but in fact, stepping inside with a javascript debugger, i've not seen any of the two classes being instantiated.

Unfortunately could not determine where the problem is.

Discussion

  • Simone Gianni

    Simone Gianni - 2007-12-04

    Logged In: YES
    user_id=1909372
    Originator: YES

    The iterator method calls :

    return Clazz.innerTypeInstance (java.util.AbstractList, this, null);

    But, ClazzExt innerTypeInstance states that the function should be in the form *$*, in fact there is no information in this call to understand that we want a java.util.AbstractList$SimpleListIterator .

    This seems to be a bug in around lines 438/442 of ASTScriptVisitor, but cannot figure it out.

     
  • Simone Gianni

    Simone Gianni - 2007-12-05

    Logged In: YES
    user_id=1909372
    Originator: YES

    Changing :

    return Clazz.innerTypeInstance (java.util.AbstractList, this, null);

    To :

    return Clazz.innerTypeInstance (java.util.AbstractList.SimpleListIterator, this, null);

    Solves the problem, so it's a problem during generation of the call, not during generation of the inner class itself.

     
  • Zhou Renjian

    Zhou Renjian - 2007-12-05

    Logged In: YES
    user_id=1702895
    Originator: NO

    O, compiler bug. Big bug.

     
  • Zhou Renjian

    Zhou Renjian - 2007-12-05
    • labels: 856676 --> J2S Core Compiler
     
  • Zhou Renjian

    Zhou Renjian - 2007-12-12

    Logged In: YES
    user_id=1702895
    Originator: NO

    Fixed.

    Compiler trying to remove brackets results in wrong qualified name. For example:
    java.util.AbstractList<E>.SimpleListIterator results in java.util.AbstractList, which is incorrect.

    Update net.sf.j2s.core sources, export this plugin, restart Eclipse, clean and rebuilt net.sf.j2s.java.core, rebuild j2slib.z.js, ...

     
  • Zhou Renjian

    Zhou Renjian - 2007-12-12
    • status: open --> open-fixed
     
  • Zhou Renjian

    Zhou Renjian - 2008-12-01
    • status: open-fixed --> closed-fixed
     
  • Zhou Renjian

    Zhou Renjian - 2008-12-01

    Java2Script 2.0.0 was released.

     

Log in to post a comment.