Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRené Purrio2018-01-15 12:46:29 +0000
committerRené Purrio2018-01-15 12:46:29 +0000
commit7a2def0bd858ffff807a9631895561e7a95de86f (patch)
tree2214ca8cdc121f79fa6ac8fac7e160ed4f445435 /org.eclipse.core.filebuffers.tests
parent357a31b4c7ded6a2f6b68107d2ada54e8960344c (diff)
downloadeclipse.platform.text-7a2def0bd858ffff807a9631895561e7a95de86f.tar.gz
eclipse.platform.text-7a2def0bd858ffff807a9631895561e7a95de86f.tar.xz
eclipse.platform.text-7a2def0bd858ffff807a9631895561e7a95de86f.zip
Bug 529816 - [sonar] Resolve "Possible null pointer dereference"
Change-Id: I23fe76a2f516770d8917d33a6c61d3b47d4fc397 Signed-off-by: René Purrio <rpurrio@itemis.de>
Diffstat (limited to 'org.eclipse.core.filebuffers.tests')
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java8
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java8
-rw-r--r--org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java3
3 files changed, 17 insertions, 2 deletions
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java
index d86cf604344..a47231d511d 100644
--- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileBuffersForNonExistingWorkspaceFiles.java
@@ -14,6 +14,8 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+import java.io.IOException;
+
import org.junit.After;
import org.junit.Test;
@@ -68,7 +70,11 @@ public class FileBuffersForNonExistingWorkspaceFiles extends FileBufferFunctions
@Test
public void testBug118199_fixed() throws Exception {
- IFile file= getProject().getWorkspace().getRoot().getFileForLocation(getPath());
+ IPath location= getPath();
+ IFile file= getProject().getWorkspace().getRoot().getFileForLocation(location);
+ if (file == null) {
+ throw new IOException("File '" + location + "' can not be found."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
IPath path= file.getFullPath();
assertFalse(file.exists());
fManager.connect(path, LocationKind.IFILE, null);
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java
index 235b8f55b5a..76efc9dbb13 100644
--- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileStoreFileBuffersForNonExistingWorkspaceFiles.java
@@ -12,6 +12,8 @@ package org.eclipse.core.filebuffers.tests;
import static org.junit.Assert.*;
+import java.io.IOException;
+
import org.junit.After;
import org.junit.Test;
@@ -66,7 +68,11 @@ public class FileStoreFileBuffersForNonExistingWorkspaceFiles extends FileStoreF
@Test
public void testBug118199_fixed() throws Exception {
- IFile file= getProject().getWorkspace().getRoot().getFileForLocation(getPath());
+ IPath location= getPath();
+ IFile file= getProject().getWorkspace().getRoot().getFileForLocation(location);
+ if (file == null) {
+ throw new IOException("File '" + location + "' can not be found."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
IPath path= file.getFullPath();
assertFalse(file.exists());
fManager.connect(path, LocationKind.IFILE, null);
diff --git a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java
index 022c8c94de8..cf984534842 100644
--- a/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java
+++ b/org.eclipse.core.filebuffers.tests/src/org/eclipse/core/filebuffers/tests/FileTool.java
@@ -162,6 +162,9 @@ public class FileTool {
public static void copy(File src, File dst) throws IOException {
if(src.isDirectory()){
String[] srcChildren = src.list();
+ if (srcChildren == null) {
+ throw new IOException("Content from directory '" + src.getAbsolutePath() + "' can not be listed."); //$NON-NLS-1$ //$NON-NLS-2$
+ }
for(int i = 0; i < srcChildren.length; ++i){
File srcChild= new File(src, srcChildren[i]);
File dstChild= new File(dst, srcChildren[i]);

Back to the top