diff options
author | Karsten Thoms | 2019-09-26 21:31:25 +0000 |
---|---|---|
committer | Karsten Thoms | 2019-09-26 21:31:25 +0000 |
commit | 17002c7e175bd394dd73c7f9e8680e2228a4d2b9 (patch) | |
tree | 6e54e9d47e121f31e5dfe78d36cedf552f97d030 | |
parent | 41004c3736c509f6d2a2c0f90bca66126054c21f (diff) | |
download | eclipse.platform.team-17002c7e175bd394dd73c7f9e8680e2228a4d2b9.tar.gz eclipse.platform.team-17002c7e175bd394dd73c7f9e8680e2228a4d2b9.tar.xz eclipse.platform.team-17002c7e175bd394dd73c7f9e8680e2228a4d2b9.zip |
Bug 551542 - Avoid handling of NullPointerExceptionS4_14_0_M1I20191009-1800I20191009-0600I20191009-0300I20191008-1800I20191008-0600I20191007-1800I20191007-0625I20191007-0430I20191006-1800I20191006-0600I20191003-1800I20191002-1800
Check IResource#getLocation() for null result instead of handling this
situation by catching NPEs.
Change-Id: I262a7b50d055d9dd83dbf736d413a2d6c66e1063
Signed-off-by: Karsten Thoms <karsten.thoms@itemis.de>
-rw-r--r-- | bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java index 475fb97e6..1d1cf7442 100644 --- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java +++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/internal/patch/InputPatchPage.java @@ -293,13 +293,15 @@ public class InputPatchPage extends WizardPage { IResource[] resources= Utilities.getResources(fTreeViewer.getSelection()); IResource patchFile= resources[0]; if (patchFile != null) { - try { - reader= new FileReader(patchFile.getLocation().toFile()); - } catch (FileNotFoundException ex) { - MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, PatchMessages.InputPatchPage_PatchFileNotFound_message); - } catch (NullPointerException nex) { - //in case the path doesn't exist (eg. getLocation() returned null) + if (patchFile.getLocation() == null) { MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, PatchMessages.InputPatchPage_PatchFileNotFound_message); + } else { + try { + reader = new FileReader(patchFile.getLocation().toFile()); + } catch (FileNotFoundException ex) { + MessageDialog.openError(null, PatchMessages.InputPatchPage_PatchErrorDialog_title, + PatchMessages.InputPatchPage_PatchFileNotFound_message); + } } } fPatchSource= PatchMessages.InputPatchPage_WorkspacePatch_title; @@ -838,7 +840,7 @@ public class InputPatchPage extends WizardPage { // readjust selection if there is a patch selected in the workspace or on the clipboard // check workspace first IResource patchTarget= fPatchWizard.getTarget(); - if (patchTarget instanceof IFile) { + if (patchTarget instanceof IFile && patchTarget.getLocation() != null) { Reader reader= null; try { try { @@ -854,10 +856,7 @@ public class InputPatchPage extends WizardPage { } } catch (FileNotFoundException ex) { // silently ignored - } catch (NullPointerException nex) { - // silently ignored } - } finally { if (reader != null) { try { |