NoSuchElementException in PropertyMapIterator
Hannes Wallnöfer
hannes.wallnoefer at oracle.com
Mon Dec 5 13:22:27 UTC 2016
Hi Ahmed,
yes, this is a bug, thanks for reporting it.
Out of curiosity, , since it is not an exported API class: How are you using PropertyMap?
Hannes
> Am 03.12.2016 um 10:00 schrieb Ahmed Ashour <asashour at yahoo.com>:
>
> 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); } } }}
More information about the nashorn-dev
mailing list