From 74b6597e3a4c61f84321f72eb1f5be186f2a6e51 Mon Sep 17 00:00:00 2001 From: Stephane Bailliez Date: Mon, 4 Nov 2002 17:37:05 +0000 Subject: [PATCH] Fixed NPEs that could have been flying if ant.home was not defined PR: 14232 Reported by: darin_swanson@oti.com (Darin Swanson) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@273483 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/Diagnostics.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/org/apache/tools/ant/Diagnostics.java b/src/main/org/apache/tools/ant/Diagnostics.java index a4d32ccbc..4a332b544 100644 --- a/src/main/org/apache/tools/ant/Diagnostics.java +++ b/src/main/org/apache/tools/ant/Diagnostics.java @@ -55,13 +55,13 @@ package org.apache.tools.ant; 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 final class Diagnostics { */ 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 @@ public final class Diagnostics { }; // 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 @@ public final class Diagnostics { * @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)");