You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by an...@apache.org on 2012/04/23 12:13:57 UTC

svn commit: r1329161 [1/2] - in /openejb/trunk/openejb: arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/ arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/ arquillian-tome...

Author: andygumbrecht
Date: Mon Apr 23 10:13:56 2012
New Revision: 1329161

URL: http://svn.apache.org/viewvc?rev=1329161&view=rev
Log:
Fix 'all' File.listFiles() calls - This call may return null and needs to be checked wherever it is used.
Added better logging RemoteTomEEContainer on failure.

Modified:
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/MoviesSeleniumTest.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
    openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/test/resources/arquillian.xml
    openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/ResourceFinder.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/AnnotationFinder.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/DirectoryMonitor.java
    openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckDescriptorLocationTestFileDeletionHelper.java
    openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/ValidationKeysAuditorTest.java
    openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
    openejb/trunk/openejb/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/RemoteTestServer.java
    openejb/trunk/openejb/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
    openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/ResourceFinder.java
    openejb/trunk/openejb/server/openejb-common-cli/src/main/java/org/apache/openejb/server/cli/command/LsCommand.java
    openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/AbstractContainers.java
    openejb/trunk/openejb/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/TomcatWebAppBuilder.java
    openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Installer.java
    openejb/trunk/openejb/tomee/tomee-common/src/main/java/org/apache/tomee/installer/Paths.java
    openejb/trunk/openejb/tomee/tomee-embedded/src/main/java/org/apache/tomee/embedded/Container.java
    openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/OpenEJBListener.java
    openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatEmbedder.java
    openejb/trunk/openejb/tomee/tomee-loader/src/main/java/org/apache/tomee/loader/TomcatHelper.java
    openejb/trunk/openejb/utils/webdeployer/src/main/java/org/apache/tomee/catalina/deployer/WebappDeployer.java

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Files.java Mon Apr 23 10:13:56 2012
@@ -30,8 +30,8 @@ public class Files {
         return createTempDir("tomee", ".conf");
     }
 
-    public static File createTempDir(String prefix, String suffix) throws IOException {
-        File tempDir = File.createTempFile(prefix, suffix);
+    public static File createTempDir(final String prefix, final String suffix) throws IOException {
+        final File tempDir = File.createTempFile(prefix, suffix);
         tempDir.delete();
         tempDir.mkdirs();
         deleteOnExit(tempDir);
@@ -54,54 +54,59 @@ public class Files {
         });
     }
 
-    public static void deleteOnExit(File file) {
+    public static void deleteOnExit(final File file) {
         delete.add(file.getAbsolutePath());
     }
 
     private static void delete() {
-        for (String path : delete) {
+        for (final String path : delete) {
             delete(new File(path));
         }
     }
 
-    public static void delete(File file) {
+    public static void delete(final File file) {
         if (file.exists()) {
             if (file.isDirectory()) {
-                for (File f : file.listFiles()) {
-                    delete(f);
+                final File[] files = file.listFiles();
+                if (files != null) {
+                    for (final File f : files) {
+                        delete(f);
+                    }
                 }
             }
 
-            file.delete();
+            if(!file.delete()){
+                file.deleteOnExit();
+            }
         }
     }
 
-    public static void mkdir(File dir) {
+    public static void mkdir(final File dir) {
         if (dir.exists()) return;
         if (!dir.mkdirs()) {
             throw new IllegalStateException("cannot make directory: " + dir.getAbsolutePath());
         }
     }
 
-    public static void writable(File file) {
+    public static void writable(final File file) {
         if (!file.canWrite()) {
             throw new IllegalStateException("Not writable: " + file.getAbsolutePath());
         }
     }
 
-    public static void readable(File file) {
+    public static void readable(final File file) {
         if (!file.canRead()) {
             throw new IllegalStateException("Not readable: " + file.getAbsolutePath());
         }
     }
 
-    public static void assertDir(File file) {
+    public static void assertDir(final File file) {
         if (!file.isDirectory()) {
             throw new IllegalStateException("Not a directory: " + file.getAbsolutePath());
         }
     }
 
-    public static void assertFile(File file) {
+    public static void assertFile(final File file) {
         if (!file.isFile()) {
             throw new IllegalStateException("Not a file: " + file.getAbsolutePath());
         }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-common/src/main/java/org/apache/openejb/arquillian/common/Setup.java Mon Apr 23 10:13:56 2012
@@ -16,27 +16,18 @@
  */
 package org.apache.openejb.arquillian.common;
 
-import java.util.logging.Level;
-import java.util.logging.Logger;
 import org.apache.openejb.loader.ProvisioningUtil;
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.JarExtractor;
 import org.jboss.arquillian.container.spi.client.container.LifecycleException;
 
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FileReader;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.PrintWriter;
+import java.io.*;
 import java.net.Socket;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
  * @version $Rev$ $Date$
@@ -48,7 +39,7 @@ public class Setup {
     public static final int DEFAULT_STOP_PORT = 8005;
     public static final int DEFAULT_AJP_PORT = 8009;
 
-    public static void exportProperties(File openejbHome, TomEEConfiguration c) {
+    public static void exportProperties(final File openejbHome, final TomEEConfiguration c) {
         System.setProperty("java.naming.provider.url", "http://localhost:" + c.getHttpPort() + "/tomee/ejb");
         System.setProperty("connect.tries", "90");
         System.setProperty("server.http.port", String.valueOf(c.getHttpPort()));
@@ -58,7 +49,7 @@ public class Setup {
         System.setProperty("tomee.home", openejbHome.getAbsolutePath());
     }
 
-    public static void updateServerXml(File openejbHome, final int httpPort, final int stopPort, final int ajpPort) throws IOException {
+    public static void updateServerXml(final File openejbHome, final int httpPort, final int stopPort, final int ajpPort) throws IOException {
         final Map<String, String> replacements = new HashMap<String, String>();
         replacements.put(Integer.toString(DEFAULT_HTTP_PORT), String.valueOf(httpPort));
         replacements.put(Integer.toString(DEFAULT_STOP_PORT), String.valueOf(stopPort));
@@ -68,42 +59,59 @@ public class Setup {
     }
 
     public static File findHome(File directory) {
-        final File conf = new File(directory, "conf");
-        final File webapps = new File(directory, "webapps");
+
+        directory = directory.getAbsoluteFile();
+
+        final File f = findHomeImpl(directory);
+
+        if (null == f) {
+            LOGGER.log(Level.INFO, "Unable to find home in: " + directory);
+        }
+
+        return f;
+    }
+
+    public static File findHomeImpl(final File directory) {
+        final File conf = new File(directory, "conf").getAbsoluteFile();
+        final File webapps = new File(directory, "webapps").getAbsoluteFile();
 
         if (conf.exists() && conf.isDirectory() && webapps.exists() && webapps.isDirectory()) {
             return directory;
         }
 
-        for (File file : directory.listFiles()) {
-            if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
+        final File[] files = directory.listFiles();
+        if (null != files) {
+
+            for (final File file : files) {
+                if (".".equals(file.getName()) || "..".equals(file.getName())) continue;
 
-            final File found = findHome(file);
+                final File found = findHome(file);
 
-            if (found != null) {
-                return found;
+                if (found != null) {
+                    return found;
+                }
             }
         }
 
         return null;
     }
 
-    public static File downloadAndUnpack(File dir, String artifactID) throws LifecycleException {
+    public static File downloadAndUnpack(final File dir, final String artifactID) throws LifecycleException {
 
-        File zipFile = downloadFile(artifactID, null);
+        final File zipFile = downloadFile(artifactID, null);
 
         Zips.unzip(zipFile, dir);
 
         return findHome(dir);
     }
 
-    public static File downloadFile(String artifactName, String altUrl) {
+    public static File downloadFile(final String artifactName, final String altUrl) {
         final String cache = SystemInstance.get().getOptions().get(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, (String) null);
         System.setProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER, "target");
         try {
             final File artifact = new MavenCache().getArtifact(artifactName, altUrl);
             if (artifact == null) throw new NullPointerException(String.format("No such artifact: %s", artifactName));
-            return artifact;
+            return artifact.getAbsoluteFile();
         } finally {
             if (cache == null) {
                 System.clearProperty(ProvisioningUtil.OPENEJB_DEPLOYER_CACHE_FOLDER);
@@ -113,10 +121,10 @@ public class Setup {
         }
     }
 
-    public static boolean isRunning(int port) {
+    public static boolean isRunning(final int port) {
         try {
-            Socket socket = new Socket("localhost", port);
-            OutputStream out = socket.getOutputStream();
+            final Socket socket = new Socket("localhost", port);
+            final OutputStream out = socket.getOutputStream();
             out.close();
             return true;
         } catch (Exception e) {
@@ -124,21 +132,21 @@ public class Setup {
         }
     }
 
-    public static void replace(Map<String, String> replacements, File file) throws IOException {
+    public static void replace(final Map<String, String> replacements, final File file) throws IOException {
         BufferedReader reader = null;
         PrintWriter writer = null;
 
         try {
-            File tmpFile = copyToTempFile(file);
+            final File tmpFile = copyToTempFile(file);
             reader = new BufferedReader(new FileReader(tmpFile));
             writer = new PrintWriter(new FileWriter(file));
             String line;
 
             while ((line = reader.readLine()) != null) {
-                Iterator<String> iterator = replacements.keySet().iterator();
+                final Iterator<String> iterator = replacements.keySet().iterator();
                 while (iterator.hasNext()) {
-                    String pattern = iterator.next();
-                    String replacement = replacements.get(pattern);
+                    final String pattern = iterator.next();
+                    final String replacement = replacements.get(pattern);
 
                     line = line.replaceAll(pattern, replacement);
                 }
@@ -159,7 +167,7 @@ public class Setup {
         }
     }
 
-    private static File copyToTempFile(File file) throws IOException {
+    private static File copyToTempFile(final File file) throws IOException {
         InputStream is = null;
         OutputStream os = null;
 
@@ -188,10 +196,13 @@ public class Setup {
     public static void removeUselessWebapps(final File openejbHome) {
         final File webapps = new File(openejbHome, "webapps");
         if (webapps.isDirectory()) {
-            for (File webapp : webapps.listFiles()) {
-                final String name = webapp.getName();
-                if (webapp.isDirectory() && !name.equals("openejb") && !name.equals("tomee")) {
-                    JarExtractor.delete(webapp);
+            final File[] files = webapps.listFiles();
+            if (files != null) {
+                for (final File webapp : files) {
+                    final String name = webapp.getName();
+                    if (webapp.isDirectory() && !name.equals("openejb") && !name.equals("tomee")) {
+                        JarExtractor.delete(webapp);
+                    }
                 }
             }
         }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/MoviesSeleniumTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/MoviesSeleniumTest.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/MoviesSeleniumTest.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-moviefun-example/src/test/java/org/superbiz/moviefun/MoviesSeleniumTest.java Mon Apr 23 10:13:56 2012
@@ -78,11 +78,14 @@ public class MoviesSeleniumTest {
 		}
 		
 		if (sourceFile.isDirectory()) {
-			for (File file : sourceFile.listFiles()) {
-				if (file.getName().startsWith(".")) continue;
-				addResources(source + File.separator + file.getName(), target + File.separator + file.getName(), archive);
-			}
-		}
+            final File[] files = sourceFile.listFiles();
+            if (files != null) {
+                for (File file : files) {
+                    if (file.getName().startsWith(".")) continue;
+                    addResources(source + File.separator + file.getName(), target + File.separator + file.getName(), archive);
+                }
+            }
+        }
 	}
 
 	@Test

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-remote/src/main/java/org/apache/tomee/arquillian/remote/RemoteTomEEContainer.java Mon Apr 23 10:13:56 2012
@@ -26,6 +26,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.Map;
 import java.util.TreeMap;
+import java.util.logging.Level;
 import java.util.logging.Logger;
 
 /*
@@ -57,12 +58,13 @@ public class RemoteTomEEContainer extend
 
             container.start();
         } catch (Exception e) {
-            throw new LifecycleException("Unable to start remote container", e);
+            logger.log(Level.SEVERE, "Unable to start remote container", e);
+            throw new LifecycleException("Unable to start remote container:" + e.getMessage(), e);
         }
     }
 
     private void configure() throws LifecycleException, IOException {
-        final File workingDirectory = new File(configuration.getDir());
+        final File workingDirectory = new File(configuration.getDir()).getAbsoluteFile();
 
         if (workingDirectory.exists()) {
 
@@ -81,6 +83,8 @@ public class RemoteTomEEContainer extend
 
         if (openejbHome == null) {
             openejbHome = Setup.downloadAndUnpack(workingDirectory, configuration.getArtifactName());
+
+            logger.log(Level.INFO, "Downloaded container to: " + openejbHome);
         }
 
         Files.assertDir(openejbHome);
@@ -95,10 +99,10 @@ public class RemoteTomEEContainer extend
             Setup.removeUselessWebapps(openejbHome);
         }
 
-        if (false) {
+        if (logger.isLoggable(Level.FINE)) {
             Map<Object, Object> map = new TreeMap(System.getProperties());
             for (Map.Entry<Object, Object> entry : map.entrySet()) {
-                System.out.printf("%s = %s\n", entry.getKey(), entry.getValue());
+                logger.log(Level.FINE, String.format("%s = %s\n", entry.getKey(), entry.getValue()));
             }
         }
     }

Modified: openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/test/resources/arquillian.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/test/resources/arquillian.xml?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/test/resources/arquillian.xml (original)
+++ openejb/trunk/openejb/arquillian-tomee/arquillian-tomee-webapp-remote/src/test/resources/arquillian.xml Mon Apr 23 10:13:56 2012
@@ -16,19 +16,22 @@
     See the License for the specific language governing permissions and
     limitations under the License.
 -->
-<arquillian 
-	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
-	xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
-	
-       <container qualifier="tomee" default="true">
-           <configuration>
-               <property name="httpPort">-1</property>
-               <property name="ajpPort">-1</property>
-               <property name="stopPort">-1</property>
-               <property name="tomcatVersion">7.0.27</property>
-               <property name="version">4.0.0-beta-3-SNAPSHOT</property>
-               <property name="dir">target/apache-tomee-remote</property>
-               <property name="appWorkingDir">target/arquillian-test-working-dir</property>
-           </configuration>
-       </container>
+<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+            xmlns="http://jboss.org/schema/arquillian"
+            xsi:schemaLocation="
+      http://jboss.org/schema/arquillian
+      http://jboss.org/schema/arquillian/arquillian_1_0.xsd">
+
+    <container qualifier="tomee"
+               default="true">
+        <configuration>
+            <property name="httpPort">-1</property>
+            <property name="ajpPort">-1</property>
+            <property name="stopPort">-1</property>
+            <property name="tomcatVersion">7.0.27</property>
+            <property name="version">4.0.0-beta-3-SNAPSHOT</property>
+            <property name="dir">target/apache-tomee-remote</property>
+            <property name="appWorkingDir">target/arquillian-test-working-dir</property>
+        </configuration>
+    </container>
 </arquillian>

Modified: openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/ResourceFinder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/ResourceFinder.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/ResourceFinder.java (original)
+++ openejb/trunk/openejb/arquillian-tomee/ziplock/src/main/java/org/apache/ziplock/ResourceFinder.java Mon Apr 23 10:13:56 2012
@@ -864,11 +864,13 @@ public class ResourceFinder {
         File dir = new File(decode(location.getPath()));
         if (dir.isDirectory()) {
             File[] files = dir.listFiles();
-            for (File file : files) {
-                if (!file.isDirectory()) {
-                    String name = file.getName();
-                    URL url = file.toURI().toURL();
-                    resources.put(name, url);
+            if (files != null) {
+                for (File file : files) {
+                    if (!file.isDirectory()) {
+                        String name = file.getName();
+                        URL url = file.toURI().toURL();
+                        resources.put(name, url);
+                    }
                 }
             }
         }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentLoader.java Mon Apr 23 10:13:56 2012
@@ -277,7 +277,7 @@ public class DeploymentLoader implements
                     persistenceUrls.add((URL) otherUrl);
                 } else if (otherUrl instanceof List) {
                     final List<URL> otherList = (List<URL>) otherDD.get(name);
-                    for (URL url : otherList) {
+                    for (final URL url : otherList) {
                         if (!persistenceUrls.contains(url)) {
                             persistenceUrls.add(url);
                         }
@@ -851,20 +851,22 @@ public class DeploymentLoader implements
 
         final File libDir = new File(webInfDir, "lib");
         if (libDir.exists()) {
-            for (final File file : libDir.listFiles()) {
-                if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")) {
-                    try {
-                        webClassPath.add(file.toURI().toURL());
-                    } catch (MalformedURLException e) {
-                        logger.warning("War path bad: " + file, e);
+            final File[] list = libDir.listFiles();
+            if (list != null) {
+                for (final File file : list) {
+                    if (file.getName().endsWith(".jar") || file.getName().endsWith(".zip")) {
+                        try {
+                            webClassPath.add(file.toURI().toURL());
+                        } catch (MalformedURLException e) {
+                            logger.warning("War path bad: " + file, e);
+                        }
                     }
                 }
             }
         }
 
         // create the class loader
-        final URL[] webUrls = webClassPath.toArray(new URL[webClassPath.size()]);
-        return webUrls;
+        return webClassPath.toArray(new URL[webClassPath.size()]);
     }
 
     private void addWebservices(final WsModule wsModule) throws OpenEJBException {
@@ -1095,11 +1097,14 @@ public class DeploymentLoader implements
 
         // skip the lib and classes dir in WEB-INF
         final LinkedList<File> files = new LinkedList<File>();
-        for (final File file : webInfDir.listFiles()) {
-            if ("lib".equals(file.getName()) || "classes".equals(file.getName())) {
-                continue;
+        final File[] list = webInfDir.listFiles();
+        if (list != null) {
+            for (final File file : list) {
+                if ("lib".equals(file.getName()) || "classes".equals(file.getName())) {
+                    continue;
+                }
+                files.add(file);
             }
-            files.add(file);
         }
 
         if (files.isEmpty()) return urls;
@@ -1108,7 +1113,10 @@ public class DeploymentLoader implements
         while (!files.isEmpty()) {
             File file = files.removeFirst();
             if (file.isDirectory()) {
-                files.addAll(Arrays.asList(file.listFiles()));
+                final File[] a = file.listFiles();
+                if (a != null) {
+                    files.addAll(Arrays.asList(a));
+                }
             } else if (file.getName().endsWith(".tld")) {
                 try {
                     file = file.getCanonicalFile().getAbsoluteFile();
@@ -1402,9 +1410,12 @@ public class DeploymentLoader implements
         } else if (warFile.isDirectory()) {
             final File webInfDir = new File(warFile, "WEB-INF");
             if (webInfDir.isDirectory()) {
-                for (final File file : webInfDir.listFiles()) {
-                    if (!file.isDirectory()) {
-                        descriptors.put(file.getName(), file.toURI().toURL());
+                final File[] files = webInfDir.listFiles();
+                if (files != null) {
+                    for (final File file : files) {
+                        if (!file.isDirectory()) {
+                            descriptors.put(file.getName(), file.toURI().toURL());
+                        }
                     }
                 }
             }
@@ -1457,18 +1468,21 @@ public class DeploymentLoader implements
         scanDir(dir, files, path, true);
     }
 
-    public static void scanDir(final File dir, final Map<String, URL> files, final String path, boolean recursive) {
-        for (final File file : dir.listFiles()) {
-            if (file.isDirectory()) {
-                if (recursive) {
-                    scanDir(file, files, path + file.getName() + "/");
-                }
-            } else {
-                final String name = file.getName();
-                try {
-                    files.put(path + name, file.toURI().toURL());
-                } catch (MalformedURLException e) {
-                    logger.warning("EAR path bad: " + path + name, e);
+    public static void scanDir(final File dir, final Map<String, URL> files, final String path, final boolean recursive) {
+        final File[] dirFiles = dir.listFiles();
+        if (dirFiles != null) {
+            for (final File file : dirFiles) {
+                if (file.isDirectory()) {
+                    if (recursive) {
+                        scanDir(file, files, path + file.getName() + "/");
+                    }
+                } else {
+                    final String name = file.getName();
+                    try {
+                        files.put(path + name, file.toURI().toURL());
+                    } catch (MalformedURLException e) {
+                        logger.warning("EAR path bad: " + path + name, e);
+                    }
                 }
             }
         }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/DeploymentsResolver.java Mon Apr 23 10:13:56 2012
@@ -23,7 +23,6 @@ import org.apache.openejb.loader.Options
 import org.apache.openejb.loader.SystemInstance;
 import org.apache.openejb.util.Logger;
 import org.apache.openejb.util.URLs;
-
 import org.apache.xbean.finder.UrlSet;
 import org.apache.xbean.finder.filter.ExcludeIncludeFilter;
 import org.apache.xbean.finder.filter.Filter;
@@ -125,24 +124,28 @@ public class DeploymentsResolver impleme
         //
         ////////////////////////////////
         boolean hasNestedArchives = false;
-        for (final File file : dir.listFiles()) {
-            try {
+        final File[] dirFiles = dir.listFiles();
 
-                final URL url = file.toURI().toURL();
-                if (jarList.contains(url)) continue;
-
-                if (file.getName().endsWith(".jar") || file.getName().endsWith(".war") || file.getName().endsWith(".rar") || file.getName().endsWith(".ear")) {
-                    jarList.add(url);
-                    hasNestedArchives = true;
-                } else if (new File(file, "META-INF").exists()) { // Unpacked ear or jar
-                    jarList.add(url);
-                    hasNestedArchives = true;
-                } else if (new File(file, "WEB-INF").exists()) {  // Unpacked webapp
-                    jarList.add(url);
-                    hasNestedArchives = true;
+        if (null != dirFiles) {
+            for (final File file : dirFiles) {
+                try {
+
+                    final URL url = file.toURI().toURL();
+                    if (jarList.contains(url)) continue;
+
+                    if (file.getName().endsWith(".jar") || file.getName().endsWith(".war") || file.getName().endsWith(".rar") || file.getName().endsWith(".ear")) {
+                        jarList.add(url);
+                        hasNestedArchives = true;
+                    } else if (new File(file, "META-INF").exists()) { // Unpacked ear or jar
+                        jarList.add(url);
+                        hasNestedArchives = true;
+                    } else if (new File(file, "WEB-INF").exists()) {  // Unpacked webapp
+                        jarList.add(url);
+                        hasNestedArchives = true;
+                    }
+                } catch (Exception e) {
+                    logger.debug("loadFrom", e);
                 }
-            } catch (Exception e) {
-                logger.debug("loadFrom", e);
             }
         }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/config/RemoteServer.java Mon Apr 23 10:13:56 2012
@@ -300,10 +300,13 @@ public class RemoteServer {
 
     private File lib(String name, File... dirs) {
         for (File dir : dirs) {
-            for (File file : dir.listFiles()) {
-                if (!file.isFile()) continue;
-                if (!file.getName().endsWith(".jar")) continue;
-                if (file.getName().startsWith(name)) return file;
+            final File[] files = dir.listFiles();
+            if (files != null) {
+                for (File file : files) {
+                    if (!file.isFile()) continue;
+                    if (!file.getName().endsWith(".jar")) continue;
+                    if (file.getName().startsWith(name)) return file;
+                }
             }
         }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/AnnotationFinder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/AnnotationFinder.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/AnnotationFinder.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/AnnotationFinder.java Mon Apr 23 10:13:56 2012
@@ -198,14 +198,16 @@ public class AnnotationFinder {
 
     private void scanDir(File dir, List<String> classNames, String packageName) {
         File[] files = dir.listFiles();
-        for (File file : files) {
-            if (file.isDirectory()) {
-                scanDir(file, classNames, packageName + file.getName() + ".");
-            } else if (file.getName().endsWith(".class")) {
-                String name = file.getName();
-                name = name.replaceFirst(".class$", "");
-                if (name.contains(".")) continue;
-                classNames.add(packageName + name);
+        if (files != null) {
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    scanDir(file, classNames, packageName + file.getName() + ".");
+                } else if (file.getName().endsWith(".class")) {
+                    String name = file.getName();
+                    name = name.replaceFirst(".class$", "");
+                    if (name.contains(".")) continue;
+                    classNames.add(packageName + name);
+                }
             }
         }
     }

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/DirectoryMonitor.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/DirectoryMonitor.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/DirectoryMonitor.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/DirectoryMonitor.java Mon Apr 23 10:13:56 2012
@@ -96,21 +96,23 @@ public class DirectoryMonitor {
     private void initialize() {
         getLogger().debug("Doing initial scan of " + target.getAbsolutePath());
 
-        File[] files = (target.isDirectory()) ? target.listFiles(): new File[]{target};
+        final File[] files = (target.isDirectory()) ? target.listFiles(): new File[]{target};
 
-        for (File file : files) {
+        if (files != null) {
+            for (final File file : files) {
 
-            if (!file.canRead()) {
-                continue;
-            }
+                if (!file.canRead()) {
+                    continue;
+                }
 
-            FileInfo now = newInfo(file);
-            now.setChanging(false);
+                final FileInfo now = newInfo(file);
+                now.setChanging(false);
+            }
         }
     }
 
-    private FileInfo newInfo(File child) {
-        FileInfo fileInfo = child.isDirectory() ? new DirectoryInfo(child) : new FileInfo(child);
+    private FileInfo newInfo(final File child) {
+        final FileInfo fileInfo = child.isDirectory() ? new DirectoryInfo(child) : new FileInfo(child);
         files.put(fileInfo.getPath(), fileInfo);
         return fileInfo;
     }
@@ -120,47 +122,49 @@ public class DirectoryMonitor {
      */
     public void scan() {
 
-        File[] files = (target.isDirectory()) ? target.listFiles(): new File[]{target};
+        final File[] files = (target.isDirectory()) ? target.listFiles(): new File[]{target};
 
-        HashSet<String> missingFilesList = new HashSet(this.files.keySet());
+        final HashSet<String> missingFilesList = new HashSet<String>(this.files.keySet());
 
-        for (File file : files) {
+        if (files != null) {
+            for (final File file : files) {
 
-            missingFilesList.remove(file.getAbsolutePath());
+                missingFilesList.remove(file.getAbsolutePath());
 
-            if (!file.canRead()) {
-                getLogger().debug("not readable " + file.getName());
-                continue;
-            }
+                if (!file.canRead()) {
+                    getLogger().debug("not readable " + file.getName());
+                    continue;
+                }
 
-            FileInfo oldStatus = oldInfo(file);
-            FileInfo newStatus = newInfo(file);
+                final FileInfo oldStatus = oldInfo(file);
+                final FileInfo newStatus = newInfo(file);
 
-            newStatus.diff(oldStatus);
+                newStatus.diff(oldStatus);
 
-            if (oldStatus == null) {
-                // Brand new, but assume it's changing and
-                // wait a bit to make sure it's not still changing
-                getLogger().debug("File Discovered: " + newStatus);
-            } else if (newStatus.isChanging()) {
-                // The two records are different -- record the latest as a file that's changing
-                // and later when it stops changing we'll do the add or update as appropriate.
-                getLogger().debug("File Changing: " + newStatus);
-            } else if (oldStatus.isNewFile()) {
-                // Used to be changing, now in (hopefully) its final state
-                getLogger().info("New File: " + newStatus);
-                newStatus.setNewFile(!listener.fileAdded(file));
-            } else if (oldStatus.isChanging()) {
-                getLogger().info("Updated File: " + newStatus);
-                listener.fileUpdated(file);
+                if (oldStatus == null) {
+                    // Brand new, but assume it's changing and
+                    // wait a bit to make sure it's not still changing
+                    getLogger().debug("File Discovered: " + newStatus);
+                } else if (newStatus.isChanging()) {
+                    // The two records are different -- record the latest as a file that's changing
+                    // and later when it stops changing we'll do the add or update as appropriate.
+                    getLogger().debug("File Changing: " + newStatus);
+                } else if (oldStatus.isNewFile()) {
+                    // Used to be changing, now in (hopefully) its final state
+                    getLogger().info("New File: " + newStatus);
+                    newStatus.setNewFile(!listener.fileAdded(file));
+                } else if (oldStatus.isChanging()) {
+                    getLogger().info("Updated File: " + newStatus);
+                    listener.fileUpdated(file);
 
-                missingFilesList.remove(oldStatus.getPath());
+                    missingFilesList.remove(oldStatus.getPath());
+                }
+                // else it's just totally unchanged and we ignore it this pass
             }
-            // else it's just totally unchanged and we ignore it this pass
         }
 
         // Look for any files we used to know about but didn't find in this pass
-        for (String path : missingFilesList) {
+        for (final String path : missingFilesList) {
             getLogger().info("File removed: " + path);
 
             if (listener.fileRemoved(new File(path))) {
@@ -169,7 +173,7 @@ public class DirectoryMonitor {
         }
     }
 
-    private FileInfo oldInfo(File file) {
+    private FileInfo oldInfo(final File file) {
         return (FileInfo) files.get(file.getAbsolutePath());
     }
 
@@ -201,24 +205,24 @@ public class DirectoryMonitor {
             assert dir != null;
 
             long value = dir.lastModified();
-            File[] children = dir.listFiles();
+            final File[] children = dir.listFiles();
             long test;
 
-            for (int i = 0; i < children.length; i++) {
-                File child = children[i];
-
-                if (!child.canRead()) {
-                    continue;
-                }
-
-                if (child.isDirectory()) {
-                    test = getLastModifiedInDir(child);
-                } else {
-                    test = child.lastModified();
-                }
-
-                if (test > value) {
-                    value = test;
+            if (children != null) {
+                for (final File child : children) {
+                    if (!child.canRead()) {
+                        continue;
+                    }
+
+                    if (child.isDirectory()) {
+                        test = getLastModifiedInDir(child);
+                    } else {
+                        test = child.lastModified();
+                    }
+
+                    if (test > value) {
+                        value = test;
+                    }
                 }
             }
 

Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/UrlCache.java Mon Apr 23 10:13:56 2012
@@ -53,19 +53,19 @@ public class UrlCache {
     
     private final Map<String, Map<URL, File>> cache = new TreeMap<String, Map<URL, File>>();
 
-    public synchronized URL[] cacheUrls(String appId, URL[] urls) {
+    public synchronized URL[] cacheUrls(final String appId, final URL[] urls) {
         if (!antiJarLocking) {
             return urls;
         }
 
         // the final cached urls
-        LinkedHashSet<URL> cachedUrls = new LinkedHashSet<URL>();
+        final LinkedHashSet<URL> cachedUrls = new LinkedHashSet<URL>();
 
         // this stack contains the urls to be processed... when manifest class path entries
         // are added they are added to the top (front) of the stack so manifest order is maintained
-        LinkedList<URL> locationStack = new LinkedList<URL>(Arrays.asList(urls));
+        final LinkedList<URL> locationStack = new LinkedList<URL>(Arrays.asList(urls));
         while (!locationStack.isEmpty()) {
-            URL url = locationStack.removeFirst();
+            final URL url = locationStack.removeFirst();
 
             // Skip any duplicate urls in the claspath
             if (cachedUrls.contains(url)) {
@@ -73,7 +73,7 @@ public class UrlCache {
             }
 
             // cache the URL
-            File file = cacheUrl(appId, url);
+            final File file = cacheUrl(appId, url);
 
             // if the url was successfully cached, process it's manifest classpath
             if (file != null) {
@@ -81,7 +81,7 @@ public class UrlCache {
                     cachedUrls.add(file.toURI().toURL());
 
                     // push the manifest classpath on the stack (make sure to maintain the order)
-                    List<URL> manifestClassPath = getManifestClassPath(url, file);
+                    final List<URL> manifestClassPath = getManifestClassPath(url, file);
                     locationStack.addAll(0, manifestClassPath);
                 } catch (MalformedURLException e) {
                     // invalid cache file - this should never happen
@@ -97,12 +97,12 @@ public class UrlCache {
         return cachedUrls.toArray(new URL[cachedUrls.size()]);
     }
 
-    public synchronized void releaseUrls(String appId) {
+    public synchronized void releaseUrls(final String appId) {
         logger.debug("Releasing URLs for application " + appId);
 
-        Map<URL, File> urlFileMap = cache.remove(appId);
+        final Map<URL, File> urlFileMap = cache.remove(appId);
         if (urlFileMap != null) {
-            for (File file : urlFileMap.values()) {
+            for (final File file : urlFileMap.values()) {
                 if (file.delete()) {
                     logger.debug("Deleted cached file " + file);
                 } else {
@@ -112,25 +112,25 @@ public class UrlCache {
         }
     }
 
-    public File getUrlCachedName(String appId, URL url) {
-        Map<URL, File> appCache = getAppCache(appId);
+    public File getUrlCachedName(final String appId, final URL url) {
+        final Map<URL, File> appCache = getAppCache(appId);
         if (appCache.containsKey(url)) {
             return appCache.get(url);
         }
         return null;
     }
 
-    public boolean isUrlCached(String appId, URL url) {
-        Map<URL, File> appCache = getAppCache(appId);
+    public boolean isUrlCached(final String appId, final URL url) {
+        final Map<URL, File> appCache = getAppCache(appId);
         return appCache.containsKey(url);
     }
 
-    public URL getUrlKeyCached(String appId, File file) {
+    public URL getUrlKeyCached(final String appId, final File file) {
     	if (file == null) {
     		return null;
     	}
         final Map<URL, File> appCache = getAppCache(appId);
-        for (Map.Entry<URL, File> entry : appCache.entrySet()) {
+        for (final Map.Entry<URL, File> entry : appCache.entrySet()) {
         	if (entry.getValue().equals(file)) {
         		return entry.getKey();
         	}
@@ -148,7 +148,7 @@ public class UrlCache {
         return null;
     }
 
-    private synchronized File cacheUrl(String appId, URL url) {
+    private synchronized File cacheUrl(final String appId, URL url) {
         File sourceFile;
         if (!"file".equals(url.getProtocol())) {
             // todo: download the jar ourselves?
@@ -178,7 +178,7 @@ public class UrlCache {
         }
 
         // check if file is already cached
-        Map<URL, File> appCache = getAppCache(appId);
+        final Map<URL, File> appCache = getAppCache(appId);
         if (appCache.containsKey(url)) {
             return appCache.get(url);
         }
@@ -191,8 +191,8 @@ public class UrlCache {
         }
 
         // generate a nice cache file name
-        String name = sourceFile.getName();
-        int dot = name.lastIndexOf(".");
+        final String name = sourceFile.getName();
+        final int dot = name.lastIndexOf(".");
         String prefix = name;
         String suffix = "";
         if (dot > 0) {
@@ -224,7 +224,7 @@ public class UrlCache {
         }
     }
 
-    private synchronized Map<URL, File> getAppCache(String appId) {
+    private synchronized Map<URL, File> getAppCache(final String appId) {
         Map<URL, File> urlFileMap = cache.get(appId);
         if (urlFileMap == null) {
             urlFileMap = new LinkedHashMap<URL, File>();
@@ -233,29 +233,29 @@ public class UrlCache {
         return urlFileMap;
     }
 
-    private List<URL> getManifestClassPath(URL codeSource, File location) {
+    private List<URL> getManifestClassPath(final URL codeSource, final File location) {
         try {
             // get the manifest, if possible
-            Manifest manifest = loadManifest(location);
+            final Manifest manifest = loadManifest(location);
             if (manifest == null) {
                 // some locations don't have a manifest
                 return Collections.emptyList();
             }
 
             // get the class-path attribute, if possible
-            String manifestClassPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
+            final String manifestClassPath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
             if (manifestClassPath == null) {
                 return Collections.emptyList();
             }
 
             // build the urls...
             // the class-path attribute is space delimited
-            LinkedList<URL> classPathUrls = new LinkedList<URL>();
+            final LinkedList<URL> classPathUrls = new LinkedList<URL>();
             for (StringTokenizer tokenizer = new StringTokenizer(manifestClassPath, " "); tokenizer.hasMoreTokens();) {
-                String entry = tokenizer.nextToken();
+                final String entry = tokenizer.nextToken();
                 try {
                     // the class path entry is relative to the resource location code source
-                    URL entryUrl = new URL(codeSource, entry);
+                    final URL entryUrl = new URL(codeSource, entry);
                     classPathUrls.addLast(entryUrl);
                 } catch (MalformedURLException ignored) {
                     // most likely a poorly named entry
@@ -268,24 +268,24 @@ public class UrlCache {
         }
     }
 
-    private Manifest loadManifest(File location) throws IOException {
+    private Manifest loadManifest(final File location) throws IOException {
         if (location.isDirectory()) {
-            File manifestFile = new File(location, "META-INF/MANIFEST.MF");
+            final File manifestFile = new File(location, "META-INF/MANIFEST.MF");
 
             if (manifestFile.isFile() && manifestFile.canRead()) {
                 InputStream in = null;
                 try {
                     in = IO.read(manifestFile);
-                    Manifest manifest = new Manifest(in);
+                    final Manifest manifest = new Manifest(in);
                     return manifest;
                 } finally {
                     close(in);
                 }
             }
         } else {
-            JarFile jarFile = new JarFile(location);
+            final JarFile jarFile = new JarFile(location);
             try {
-                Manifest manifest = jarFile.getManifest();
+                final Manifest manifest = jarFile.getManifest();
                 return manifest;
             } finally {
                 close(jarFile);
@@ -296,7 +296,7 @@ public class UrlCache {
 
     private static File createCacheDir() {
         try {
-            FileUtils openejbBase = SystemInstance.get().getBase();
+            final FileUtils openejbBase = SystemInstance.get().getBase();
 
             File dir = null;
             // if we are not embedded, cache (temp) dir is under base dir
@@ -332,7 +332,7 @@ public class UrlCache {
         }
     }
 
-    private static File createCacheDir(File dir) throws IOException {
+    private static File createCacheDir(final File dir) throws IOException {
         
         if(dir.exists() && dir.isDirectory()){
             return dir;
@@ -357,14 +357,14 @@ public class UrlCache {
      *
      * @param dir File object representing the directory to be deleted
      */
-    public static void deleteDir(File dir) {
+    public static void deleteDir(final File dir) {
         if (dir == null) {
             return;
         }
 
-        File[] fileNames = dir.listFiles();
+        final File[] fileNames = dir.listFiles();
         if (fileNames != null) {
-            for (File file : fileNames) {
+            for (final File file : fileNames) {
                 if (file.isDirectory()) {
                     deleteDir(file);
                 } else {
@@ -384,7 +384,7 @@ public class UrlCache {
         }
     }
 
-    private static void close(Closeable closeable) {
+    private static void close(final Closeable closeable) {
         if (closeable != null) {
             try {
                 closeable.close();
@@ -393,7 +393,7 @@ public class UrlCache {
         }
     }
 
-    private static void close(JarFile closeable) {
+    private static void close(final JarFile closeable) {
         if (closeable != null) {
             try {
                 closeable.close();

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/DependenceValidationTest.java Mon Apr 23 10:13:56 2012
@@ -98,11 +98,14 @@ public class DependenceValidationTest ex
     }
 
     private static void dir(File dir, DependencyVisitor dependencyVisitor) {
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory()) {
-                dir(file, dependencyVisitor);
-            } else if (file.getName().endsWith(".class")) {
-                file(file, dependencyVisitor);
+        final File[] files = dir.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    dir(file, dependencyVisitor);
+                } else if (file.getName().endsWith(".class")) {
+                    file(file, dependencyVisitor);
+                }
             }
         }
     }

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckDescriptorLocationTestFileDeletionHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckDescriptorLocationTestFileDeletionHelper.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckDescriptorLocationTestFileDeletionHelper.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/CheckDescriptorLocationTestFileDeletionHelper.java Mon Apr 23 10:13:56 2012
@@ -19,6 +19,7 @@ package org.apache.openejb.config;
 import org.junit.Test;
 
 import java.io.File;
+import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.List;
 
@@ -30,7 +31,13 @@ public class CheckDescriptorLocationTest
     public void deleteFile() {
         File fileLocation = new File(System.getProperty("java.io.tmpdir"));
         assertTrue(fileLocation.isDirectory());
-        List<File> asList = Arrays.asList(fileLocation.listFiles());
+        final File[] list = fileLocation.listFiles();
+        List<File> asList = null;
+        if (list != null) {
+            asList = Arrays.asList(list);
+        } else{
+            asList = new ArrayList<File>();
+        }
         deleteTestCreatedFiles(asList);
 
     }

Modified: openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/ValidationKeysAuditorTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/ValidationKeysAuditorTest.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/ValidationKeysAuditorTest.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/test/java/org/apache/openejb/config/rules/ValidationKeysAuditorTest.java Mon Apr 23 10:13:56 2012
@@ -321,11 +321,14 @@ public class ValidationKeysAuditorTest {
     }
 
     private static void dir(File dir, KeysAnnotationVisitor visitor) {
-        for (File file : dir.listFiles()) {
-            if (file.isDirectory()) {
-                dir(file, visitor);
-            } else if (file.getName().endsWith(".class")) {
-                file(file, visitor);
+        final File[] files = dir.listFiles();
+        if (files != null) {
+            for (File file : files) {
+                if (file.isDirectory()) {
+                    dir(file, visitor);
+                } else if (file.getName().endsWith(".class")) {
+                    file(file, visitor);
+                }
             }
         }
     }

Modified: openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java (original)
+++ openejb/trunk/openejb/container/openejb-loader/src/main/java/org/apache/openejb/loader/Files.java Mon Apr 23 10:13:56 2012
@@ -177,7 +177,9 @@ public class Files {
                 }
             }
 
-            file.delete();
+            if(!file.delete()){
+                file.deleteOnExit();
+            }
         }
     }
 

Modified: openejb/trunk/openejb/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/RemoteTestServer.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/RemoteTestServer.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/RemoteTestServer.java (original)
+++ openejb/trunk/openejb/itests/openejb-itests-client/src/main/java/org/apache/openejb/test/RemoteTestServer.java Mon Apr 23 10:13:56 2012
@@ -64,10 +64,12 @@ public class RemoteTestServer implements
                 File openejbJar = null;
                 final File lib = new File(home, "lib");
                 final File[] files = lib.listFiles();
-                for (int i = 0; i < files.length && openejbJar == null; i++) {
-                    final File file = files[i];
-                    if (file.getName().startsWith("openejb-core") && file.getName().endsWith("jar")) {
-                        openejbJar = file;
+                if (null != files) {
+                    for (int i = 0; i < files.length && openejbJar == null; i++) {
+                        final File file = files[i];
+                        if (file.getName().startsWith("openejb-core") && file.getName().endsWith("jar")) {
+                            openejbJar = file;
+                        }
                     }
                 }
 

Modified: openejb/trunk/openejb/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java (original)
+++ openejb/trunk/openejb/maven/tomee-maven-plugin/src/main/java/org/apache/openejb/maven/plugin/AbstractTomEEMojo.java Mon Apr 23 10:13:56 2012
@@ -348,22 +348,25 @@ public abstract class AbstractTomEEMojo 
             return;
         }
 
-        for (File f : dir.listFiles()) {
-            if (f.isDirectory() || f.isHidden()) {
-                continue;
-            }
+        final File[] files = dir.listFiles();
+        if (files != null) {
+            for (final File f : files) {
+                if (f.isDirectory() || f.isHidden()) {
+                    continue;
+                }
 
-            InputStream in = null;
-            OutputStream out = null;
-            try {
-                in = new FileInputStream(f);
-                out = new FileOutputStream(new File(catalinaBase, dir.getName() + "/" + f.getName()));
-                copy(in, out);
-            } catch (Exception e) {
-                throw new TomEEException(e.getMessage(), e);
-            } finally {
-                close(in);
-                close(out);
+                InputStream in = null;
+                OutputStream out = null;
+                try {
+                    in = new FileInputStream(f);
+                    out = new FileOutputStream(new File(catalinaBase, dir.getName() + "/" + f.getName()));
+                    copy(in, out);
+                } catch (Exception e) {
+                    throw new TomEEException(e.getMessage(), e);
+                } finally {
+                    close(in);
+                    close(out);
+                }
             }
         }
     }

Modified: openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/ResourceFinder.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/ResourceFinder.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/ResourceFinder.java (original)
+++ openejb/trunk/openejb/server/openejb-client/src/main/java/org/apache/openejb/client/ResourceFinder.java Mon Apr 23 10:13:56 2012
@@ -859,11 +859,13 @@ public class ResourceFinder {
         File dir = new File(URLDecoder.decode(location.getPath()));
         if (dir.isDirectory()) {
             File[] files = dir.listFiles();
-            for (File file : files) {
-                if (!file.isDirectory()) {
-                    String name = file.getName();
-                    URL url = file.toURI().toURL();
-                    resources.put(name, url);
+            if (files != null) {
+                for (File file : files) {
+                    if (!file.isDirectory()) {
+                        String name = file.getName();
+                        URL url = file.toURI().toURL();
+                        resources.put(name, url);
+                    }
                 }
             }
         }

Modified: openejb/trunk/openejb/server/openejb-common-cli/src/main/java/org/apache/openejb/server/cli/command/LsCommand.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-common-cli/src/main/java/org/apache/openejb/server/cli/command/LsCommand.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-common-cli/src/main/java/org/apache/openejb/server/cli/command/LsCommand.java (original)
+++ openejb/trunk/openejb/server/openejb-common-cli/src/main/java/org/apache/openejb/server/cli/command/LsCommand.java Mon Apr 23 10:13:56 2012
@@ -44,8 +44,11 @@ public class LsCommand extends PathComma
         if (!base.endsWith("/")) {
             removed = removed + "/";
         }
-        for (File file : dir.listFiles()) { // not recursive otherwise it starts to be complicated
-            streamManager.writeOut(type(file) + " " + file.getAbsolutePath().replace(removed, ""));
+        final File[] files = dir.listFiles();
+        if (files != null) {
+            for (final File file : files) { // not recursive otherwise it starts to be complicated
+                streamManager.writeOut(type(file) + " " + file.getAbsolutePath().replace(removed, ""));
+            }
         }
     }
 

Modified: openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/AbstractContainers.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/AbstractContainers.java?rev=1329161&r1=1329160&r2=1329161&view=diff
==============================================================================
--- openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/AbstractContainers.java (original)
+++ openejb/trunk/openejb/tck/tck-common/src/main/java/org/apache/openejb/tck/impl/AbstractContainers.java Mon Apr 23 10:13:56 2012
@@ -29,14 +29,14 @@ import java.io.InputStream;
 public class AbstractContainers {
     protected static final String tmpDir = System.getProperty("java.io.tmpdir");
 
-    protected void writeToFile(File file, InputStream archive) {
+    protected void writeToFile(final File file, final InputStream archive) {
         if (!file.getParentFile().exists()) {
             file.getParentFile().mkdirs();
         }
 
         try {
-            FileOutputStream fos = new FileOutputStream(file);
-            byte[] buffer = new byte[4096];
+            final FileOutputStream fos = new FileOutputStream(file);
+            final byte[] buffer = new byte[4096];
             int bytesRead;
             while ((bytesRead = archive.read(buffer)) > -1) {
                 fos.write(buffer, 0, bytesRead);
@@ -47,10 +47,13 @@ public class AbstractContainers {
         }
     }
 
-    protected static void delete(File file) {
+    protected static void delete(final File file) {
         if (file.isDirectory()) {
-            for (File f : file.listFiles()) {
-                delete(f);
+            final File[] files = file.listFiles();
+            if (files != null) {
+                for (final File f : files) {
+                    delete(f);
+                }
             }
         }
         if (!file.delete()) {
@@ -59,7 +62,7 @@ public class AbstractContainers {
     }
 
     protected static final class Util {
-        static void close(Closeable closeable) throws IOException {
+        static void close(final Closeable closeable) throws IOException {
             if (closeable == null)
                 return;
             try {