webwork/src/main/webwork/util/classloader DirectoryClassLoader.java,1.1,1.2

[email protected] Fri, 2 Sep 2005 11:39:36 +0000 (UTC)
Newsgroups gmane.comp.java.open-symphony.cvs
Message-ID <[email protected]>
Update of /cvsroot/opensymphony/webwork/src/main/webwork/util/classloader
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv3412/src/main/webwork/util/classloader

Modified Files:
	DirectoryClassLoader.java 
Log Message:
Sync timestamps to avoid ConcurrentModificationException

Index: DirectoryClassLoader.java
===================================================================
RCS file: /cvsroot/opensymphony/webwork/src/main/webwork/util/classloader/DirectoryClassLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- DirectoryClassLoader.java	9 Nov 2003 21:02:17 -0000	1.1
+++ DirectoryClassLoader.java	2 Sep 2005 09:44:02 -0000	1.2
@@ -27,15 +27,18 @@
 
   public boolean isStale()
   {
-    Iterator iter = timestamps.entrySet().iterator();
-    while(iter.hasNext())
+    synchronized(timestamps)
     {
-      Map.Entry entry = (Map.Entry)iter.next();
-      File toCheck = new File(directory, (String)entry.getKey());
-      long time = ((Long)entry.getValue()).longValue();
-      if(toCheck.lastModified() > time)
+      Iterator iter = timestamps.entrySet().iterator();
+      while(iter.hasNext())
       {
-        return true;
+        Map.Entry entry = (Map.Entry)iter.next();
+        File toCheck = new File(directory, (String)entry.getKey());
+        long time = ((Long)entry.getValue()).longValue();
+        if(toCheck.lastModified() > time)
+        {
+          return true;
+        }
       }
     }
     return false;
@@ -50,19 +53,18 @@
   {
     try
     {
-      InputStream in = null;
-      int size = 0;
 
       File f = new File(directory, path);
       if(!f.exists()) return null;
-        size = (int)f.length();
-        in = new FileInputStream(f);
-        //we're ok not storing timestamps for jars, since the whole jar
-        //will be modified in that case.
+      int size = (int)f.length();
+      InputStream in = new FileInputStream(f);
+      //we're ok not storing timestamps for jars, since the whole jar
+      //will be modified in that case.
+      synchronized(timestamps)
+      {
         timestamps.put(path, new Long(f.lastModified()));
-
-      byte[] data = ClassLoaderUtils.readStream(in, size);
-      return data;
+      }
+      return ClassLoaderUtils.readStream(in, size);
     }
     catch(IOException e)
     {



-------------------------------------------------------
SF.Net email is Sponsored by the Better Software Conference & EXPO
September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices
Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA
Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf