From d721e4f356d2cb272b0eb47829220a5b2b23c2dc Mon Sep 17 00:00:00 2001 From: Harvey Harrison Date: Wed, 3 Apr 2013 23:55:16 -0700 Subject: gluegen: use enhanced for-loops in ArrayHashSet Fixes an infinite loop in addAll due to the following line: mod = mod || add(iter.next()) ; After the first successful add, mod will be true and thereafter iter.next will never be called again, due to || shortcutting. the loop will then run forever as any further elements will never be taken from the iterator, so hasNext will always be true. Signed-off-by: Harvey Harrison --- src/java/com/jogamp/common/util/ArrayHashSet.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/java/com/jogamp/common/util/ArrayHashSet.java') diff --git a/src/java/com/jogamp/common/util/ArrayHashSet.java b/src/java/com/jogamp/common/util/ArrayHashSet.java index 630e2af..fe5ade8 100644 --- a/src/java/com/jogamp/common/util/ArrayHashSet.java +++ b/src/java/com/jogamp/common/util/ArrayHashSet.java @@ -168,8 +168,8 @@ public class ArrayHashSet */ public final boolean addAll(Collection c) { boolean mod = false; - for (Iterator iter = c.iterator(); iter.hasNext(); ) { - mod = mod || add(iter.next()) ; + for (E o : c) { + mod |= add(o); } return mod; } @@ -195,8 +195,8 @@ public class ArrayHashSet * otherwise false. */ public final boolean containsAll(Collection c) { - for (Iterator iter = c.iterator(); iter.hasNext(); ) { - if (! this.contains(iter.next()) ) { + for (Object o : c) { + if (!this.contains(o)) { return false; } } @@ -213,8 +213,8 @@ public class ArrayHashSet */ public final boolean removeAll(Collection c) { boolean mod = false; - for (Iterator iter = c.iterator(); iter.hasNext(); ) { - mod = this.remove(iter.next()) || mod; + for (Object o : c) { + mod |= this.remove(o); } return mod; } @@ -230,10 +230,9 @@ public class ArrayHashSet */ public final boolean retainAll(Collection c) { boolean mod = false; - for (Iterator iter = this.iterator(); iter.hasNext(); ) { - Object o = iter.next(); - if (! c.contains(o) ) { - mod = this.remove(o) || mod; + for (Object o : c) { + if (!c.contains(o)) { + mod |= this.remove(o); } } return mod; -- cgit v1.2.3