Hi all,
I believe there is a bug in next() of PropertyMap.PropertyMapIterator, where 
'iter' may not have more elements.
The line should be changed from "property = iter.next();" to "property = 
iter.hasNext() ? iter.next() : null;".
This checking is done in the constructor and in skipNotEnumerable(), but not in 
next().
Below is a complete test case, that fails in jdk8 and jdk9 code bases.
Thanks a lot,Ahmed Ashour
public class PropertyMapTest {
    @Test    public  void iterator() {        ScriptObject scriptObject = new 
ObjectConstructor();        for (Object o : scriptObject.getMap()) {        }   
 }
    public static final class ObjectConstructor extends ScriptObject {        
private ScriptFunction addEventListener;
        public ScriptFunction G$addEventListener() {            return 
addEventListener;        }
        public void S$addEventListener(final ScriptFunction function) {         
   this.addEventListener = function;        }
        {            final List<Property> list = new ArrayList<>(1);            
list.add(AccessorProperty.create("addEventListener", 
Property.WRITABLE_ENUMERABLE_CONFIGURABLE,                     
virtualHandle("G$addEventListener", ScriptFunction.class),                    
virtualHandle("S$addEventListener", void.class, ScriptFunction.class)));        
    setMap(PropertyMap.newMap(list));        }
        private static MethodHandle virtualHandle(final String name, final 
Class<?> rtype, final Class<?>... ptypes) {            try {                
return MethodHandles.lookup().findVirtual(ObjectConstructor.class, name,        
                MethodType.methodType(rtype, ptypes));            }            
catch (final ReflectiveOperationException e) {                throw new 
IllegalStateException(e);            }        }    }}

Reply via email to