Bug 529661 - [sonar] Resolve "Possible null pointer dereference"

Change-Id: Iff5dd4fb95f6d2d7b5f851f5f45c3298c3ae5e39
Signed-off-by: René Purrio <rpurrio@itemis.de>
diff --git a/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/FileTool.java b/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/FileTool.java
index ef91450..e9b93fc 100644
--- a/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/FileTool.java
+++ b/bundles/org.eclipse.releng.tests/src/org/eclipse/releng/tests/FileTool.java
@@ -135,6 +135,9 @@
 	public static void copy(File root, File src, File dst) throws IOException {
 		if(src.isDirectory()){
 			String[] children = src.list();
+			if (children == null) {
+				throw new IOException("Content from directory '" + src.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$
+			}
 			for(int i = 0; i < children.length; ++i){
 				File child = new File(src, children[i]);
 				copy(root, child, dst);
@@ -158,6 +161,9 @@
 		if(file.exists()){
 			if(file.isDirectory()){
 				String[] children = file.list();
+				if(children == null) {
+					children = new String[0];
+				}
 				for(int i = 0; i < children.length; ++i) {
 					File child = new File(file, children[i]);
 					delete(child);
@@ -392,7 +398,9 @@
 	private static void unzip(IZipFilter filter, File rootDstDir, File dstDir, int depth) {
 	
 		File[] entries = rootDstDir.listFiles();
-
+		if (entries == null) {
+			entries = new File[0];
+		}
 		for (int i = 0; i < entries.length; i++) {
 			if (entries[i].isDirectory()) {
 				unzip(filter, entries[i], dstDir, depth);
@@ -447,6 +455,10 @@
 	private static void zip(File root, File file, ZipOutputStream zos) throws IOException {
 		if(file.isDirectory()){
 			String name = file.getName();
+			String[] list = file.list();
+			if (list == null) {
+				throw new IOException("Content from directory '" + file.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$
+			}
 			if(name.endsWith("_zip") || name.endsWith("_jar")){
 				String rootString = root.toString();
 				String fileString = file.toString();
@@ -456,7 +468,6 @@
 				ZipEntry zipEntry = new ZipEntry(changeSeparator(zipEntryName, File.separatorChar, '/'));
 				zos.putNextEntry(zipEntry);
 				ZipOutputStream zos2 = new ZipOutputStream(zos);
-				String[] list = file.list();
 				for(int i = 0; i < list.length; ++i){
 					File item = new File(file, list[i]);
 					zip(file, item, zos2);
@@ -464,7 +475,6 @@
 				zos2.finish();
 				zos.closeEntry();
 			} else {
-				String[] list = file.list();
 				for(int i = 0; i < list.length; ++i){
 					File item = new File(file, list[i]);
 					zip(root, item, zos);