ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sbaill...@apache.org
Subject cvs commit: jakarta-ant/src/main/org/apache/tools/ant Diagnostics.java
Date Mon, 04 Nov 2002 17:37:05 GMT
sbailliez    2002/11/04 09:37:05

  Modified:    src/main/org/apache/tools/ant Diagnostics.java
  Log:
  Fixed NPEs that could have been flying if ant.home was not defined
  PR: 14232
  Reported by: darin_swanson@oti.com (Darin Swanson)
  
  Revision  Changes    Path
  1.5       +15 -4     jakarta-ant/src/main/org/apache/tools/ant/Diagnostics.java
  
  Index: Diagnostics.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/Diagnostics.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Diagnostics.java	25 Jul 2002 15:21:01 -0000	1.4
  +++ Diagnostics.java	4 Nov 2002 17:37:05 -0000	1.5
  @@ -55,13 +55,13 @@
   
   import java.io.File;
   import java.io.FilenameFilter;
  -import java.io.IOException;
  -import java.io.InputStream;
   import java.io.PrintStream;
  -import java.lang.reflect.InvocationTargetException;
  -import java.lang.reflect.Method;
  +import java.io.InputStream;
  +import java.io.IOException;
   import java.util.Enumeration;
   import java.util.Properties;
  +import java.lang.reflect.Method;
  +import java.lang.reflect.InvocationTargetException;
   
   /**
    * A little diagnostic helper that output some information that may help
  @@ -120,6 +120,9 @@
        */
       public static File[] listLibraries() {
           String home = System.getProperty("ant.home");
  +        if (home == null) {
  +            return null;
  +        }
           File libDir = new File(home, "lib");
           FilenameFilter filter = new FilenameFilter() {
               public boolean accept(File dir, String name) {
  @@ -128,6 +131,9 @@
           };
           // listFiles is JDK 1.2+ method...
           String[] filenames = libDir.list(filter);
  +        if (filenames == null) {
  +            return null;
  +        }
           File[] files = new File[filenames.length];
           for (int i = 0; i < filenames.length; i++){
               files[i] = new File(libDir, filenames[i]);
  @@ -235,7 +241,12 @@
        * @param out the stream to print the content to
        */
       private static void doReportLibraries(PrintStream out){
  +        out.println("ant.home: " + System.getProperty("ant.home"));
           File[] libs = listLibraries();
  +        if (libs == null) {
  +            out.println("Unable to list libraries.");
  +            return;
  +        }
           for (int i = 0; i < libs.length; i++){
               out.println(libs[i].getName()
                       + " (" + libs[i].length() + " bytes)");
  
  
  

--
To unsubscribe, e-mail:   <mailto:ant-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-dev-help@jakarta.apache.org>


Mime
View raw message