Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=42077
authormarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 23 Nov 2008 23:35:05 +0000 (23:35 +0000)
committermarkt <markt@13f79535-47bb-0310-9956-ffa450edef68>
Sun, 23 Nov 2008 23:35:05 +0000 (23:35 +0000)
Don't include nulls in iterator. Based on a patch by Mathias Broekelmann

git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@720069 13f79535-47bb-0310-9956-ffa450edef68

java/javax/el/CompositeELResolver.java

index 8227e53..d4e3652 100644 (file)
@@ -19,6 +19,7 @@ package javax.el;
 
 import java.beans.FeatureDescriptor;
 import java.util.Iterator;
+import java.util.NoSuchElementException;
 
 public class CompositeELResolver extends ELResolver {
 
@@ -127,10 +128,12 @@ public class CompositeELResolver extends ELResolver {
 
         private final int size;
 
-        private Iterator itr;
+        private Iterator<FeatureDescriptor> itr;
 
         private int idx;
 
+        private FeatureDescriptor next;
+
         public FeatureIterator(ELContext context, Object base,
                 ELResolver[] resolvers, int size) {
             this.context = context;
@@ -150,22 +153,30 @@ public class CompositeELResolver extends ELResolver {
             }
         }
 
-        public boolean hasNext() {
-            return this.itr != null;
+        public boolean hasNext() {          
+            if (this.next != null)
+                return true;
+            if (this.itr != null){
+                while (this.next == null && itr.hasNext()) {
+                    this.next = itr.next();
+                }
+            } else {
+                return false;
+            }
+            if (this.next == null) {
+                this.itr = null;
+                this.guaranteeIterator();
+            }
+            return hasNext();
         }
 
         public FeatureDescriptor next() {
-            Object result = null;
-            if (this.itr != null) {
-                if (this.itr.hasNext()) {
-                    result = this.itr.next();
-                    if (!this.itr.hasNext()) {
-                        this.itr = null;
-                        this.guaranteeIterator();
-                    }
-                }
-            }
-            return (FeatureDescriptor) result;
+            if (!hasNext())
+                throw new NoSuchElementException();
+            FeatureDescriptor next = this.next;
+            this.next = null;
+            return next;
+
         }
 
         public void remove() {