Fix some concurrency handling. (FELIX-2549)


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@987626 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
index 62bd70e..9cba896 100644
--- a/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
+++ b/framework/src/main/java/org/apache/felix/framework/ModuleImpl.java
@@ -1444,7 +1444,7 @@
     }
 
     private Object doImplicitBootDelegation(Class[] classes, String name, boolean isClass)
-    throws ClassNotFoundException, ResourceNotFoundException
+        throws ClassNotFoundException, ResourceNotFoundException
     {
         // Start from 1 to skip security manager class.
         for (int i = 1; i < classes.length; i++)
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/ContentDirectoryContent.java b/framework/src/main/java/org/apache/felix/framework/cache/ContentDirectoryContent.java
index cfdde9c..263ba04 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/ContentDirectoryContent.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/ContentDirectoryContent.java
@@ -26,8 +26,8 @@
 
 public class ContentDirectoryContent implements Content
 {
-    private Content m_content = null;
-    private String m_rootPath = null;
+    private final Content m_content;
+    private final String m_rootPath;
 
     public ContentDirectoryContent(Content content, String path)
     {
@@ -37,16 +37,15 @@
             ? path + "/" : path;
     }
 
-    public synchronized void close()
+    public void close()
     {
         // We do not actually close the associated content
         // from which we are filtering our directory because
         // we assume that this will be close manually by
         // the owner of that content.
-        m_content = null;
     }
 
-    public synchronized boolean hasEntry(String name) throws IllegalStateException
+    public boolean hasEntry(String name) throws IllegalStateException
     {
         if ((name.length() > 0) && (name.charAt(0) == '/'))
         {
@@ -56,12 +55,12 @@
         return m_content.hasEntry(m_rootPath + name);
     }
 
-    public synchronized Enumeration getEntries()
+    public Enumeration getEntries()
     {
         return new EntriesEnumeration(m_content.getEntries(), m_rootPath);
     }
 
-    public synchronized byte[] getEntryAsBytes(String name) throws IllegalStateException
+    public byte[] getEntryAsBytes(String name) throws IllegalStateException
     {
         if ((name.length() > 0) && (name.charAt(0) == '/'))
         {
@@ -71,7 +70,7 @@
         return m_content.getEntryAsBytes(m_rootPath + name);
     }
 
-    public synchronized InputStream getEntryAsStream(String name)
+    public InputStream getEntryAsStream(String name)
         throws IllegalStateException, IOException
     {
         if ((name.length() > 0) && (name.charAt(0) == '/'))
@@ -109,8 +108,8 @@
 
     private static class EntriesEnumeration implements Enumeration
     {
-        private Enumeration m_enumeration = null;
-        private String m_rootPath = null;
+        private final Enumeration m_enumeration;
+        private final String m_rootPath;
         private String m_nextEntry = null;
 
         public EntriesEnumeration(Enumeration enumeration, String rootPath)
@@ -120,12 +119,12 @@
             m_nextEntry = findNextEntry();
         }
 
-        public boolean hasMoreElements()
+        public synchronized boolean hasMoreElements()
         {
             return (m_nextEntry != null);
         }
 
-        public Object nextElement()
+        public synchronized Object nextElement()
         {
             if (m_nextEntry == null)
             {
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
index 68cd6c9..9db1ca6 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/DirectoryContent.java
@@ -54,7 +54,7 @@
         // Nothing to clean up.
     }
 
-    public synchronized boolean hasEntry(String name) throws IllegalStateException
+    public boolean hasEntry(String name) throws IllegalStateException
     {
         if ((name.length() > 0) && (name.charAt(0) == '/'))
         {
@@ -64,7 +64,7 @@
         return new File(m_dir, name).exists();
     }
 
-    public synchronized Enumeration getEntries()
+    public Enumeration getEntries()
     {
         // Wrap entries enumeration to filter non-matching entries.
         Enumeration e = new EntriesEnumeration(m_dir);
@@ -73,7 +73,7 @@
         return (e.hasMoreElements()) ? e : null;
     }
 
-    public synchronized byte[] getEntryAsBytes(String name) throws IllegalStateException
+    public byte[] getEntryAsBytes(String name) throws IllegalStateException
     {
         if ((name.length() > 0) && (name.charAt(0) == '/'))
         {
@@ -120,7 +120,7 @@
         }
     }
 
-    public synchronized InputStream getEntryAsStream(String name)
+    public InputStream getEntryAsStream(String name)
         throws IllegalStateException, IOException
     {
         if ((name.length() > 0) && (name.charAt(0) == '/'))
@@ -131,7 +131,7 @@
         return new FileInputStream(new File(m_dir, name));
     }
 
-    public synchronized Content getEntryAsContent(String entryName)
+    public Content getEntryAsContent(String entryName)
     {
         // If the entry name refers to the content itself, then
         // just return it immediately.
@@ -182,7 +182,7 @@
     }
 
 // TODO: SECURITY - This will need to consider security.
-    public synchronized String getEntryAsNativeLibrary(String entryName)
+    public String getEntryAsNativeLibrary(String entryName)
     {
         // Return result.
         String result = null;
@@ -299,8 +299,8 @@
 
     private static class EntriesEnumeration implements Enumeration
     {
-        private File m_dir = null;
-        private File[] m_children = null;
+        private final File m_dir;
+        private final File[] m_children;
         private int m_counter = 0;
 
         public EntriesEnumeration(File dir)
@@ -309,12 +309,12 @@
             m_children = listFilesRecursive(m_dir);
         }
 
-        public boolean hasMoreElements()
+        public synchronized boolean hasMoreElements()
         {
             return (m_children != null) && (m_counter < m_children.length);
         }
 
-        public Object nextElement()
+        public synchronized Object nextElement()
         {
             if ((m_children == null) || (m_counter >= m_children.length))
             {
@@ -338,7 +338,7 @@
             return sb.toString();
         }
 
-        public File[] listFilesRecursive(File dir)
+        private File[] listFilesRecursive(File dir)
         {
             File[] children = dir.listFiles();
             File[] combined = children;
diff --git a/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java b/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
index 2adef24..7f7ede5 100644
--- a/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
+++ b/framework/src/main/java/org/apache/felix/framework/cache/JarContent.java
@@ -482,7 +482,7 @@
 
     private static class EntriesEnumeration implements Enumeration
     {
-        private Enumeration m_enumeration = null;
+        private final Enumeration m_enumeration;
 
         public EntriesEnumeration(Enumeration enumeration)
         {