Avoid returning duplicates of synthesized directory entries. (FELIX-2935)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@1101073 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
index ae5f8aa..fcf8e39 100644
--- a/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
+++ b/framework/src/main/java/org/apache/felix/framework/EntryFilterEnumeration.java
@@ -90,12 +90,12 @@
 
     public synchronized boolean hasMoreElements()
     {
-        return (m_nextEntries.size() != 0);
+        return !m_nextEntries.isEmpty();
     }
 
     public synchronized Object nextElement()
     {
-        if (m_nextEntries.size() == 0)
+        if (m_nextEntries.isEmpty())
         {
             throw new NoSuchElementException("No more entries.");
         }
@@ -114,11 +114,11 @@
         {
             return;
         }
-        while ((m_moduleIndex < m_enumerations.size()) && (m_nextEntries.size() == 0))
+        while ((m_moduleIndex < m_enumerations.size()) && m_nextEntries.isEmpty())
         {
             while (m_enumerations.get(m_moduleIndex) != null
                 && m_enumerations.get(m_moduleIndex).hasMoreElements()
-                && m_nextEntries.size() == 0)
+                && m_nextEntries.isEmpty())
             {
                 // Get the current entry to determine if it should be filtered or not.
                 String entryName = (String) m_enumerations.get(m_moduleIndex).nextElement();
@@ -198,7 +198,9 @@
                     // be filtered or not. If we are recursive or the current entry
                     // is a child (not a grandchild) of the initial path, then we need
                     // to check if it matches the file pattern.
-                    if (m_recurse || (dirSlashIdx < 0) || (dirSlashIdx == entryName.length() - 1))
+                    if (!m_dirEntries.contains(entryName)
+                        && (m_recurse || (dirSlashIdx < 0)
+                            || (dirSlashIdx == entryName.length() - 1)))
                     {
                         // See if the file pattern matches the last element of the path.
                         if (SimpleFilter.compareSubstring(
@@ -219,7 +221,7 @@
                     }
                 }
             }
-            if (m_nextEntries.size() == 0)
+            if (m_nextEntries.isEmpty())
             {
                 m_moduleIndex++;
             }