Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMykola Nikishov2018-07-03 08:02:03 -0400
committerMykola Nikishov2018-07-05 10:01:46 -0400
commit6b06d650c4ef2b4acf8bf2400d4b5493b7f1b704 (patch)
treedab82349b5795494aa1dc117ce771b3d76c67af9
parentd5a5e56e24e91129d1153a69989abdfc7a611fa6 (diff)
downloadeclipse.platform.team-6b06d650c4ef2b4acf8bf2400d4b5493b7f1b704.tar.gz
eclipse.platform.team-6b06d650c4ef2b4acf8bf2400d4b5493b7f1b704.tar.xz
eclipse.platform.team-6b06d650c4ef2b4acf8bf2400d4b5493b7f1b704.zip
Bug 326103 - NPE when comparing two projectsI20180705-2000
Even when MergeSourceViewer's getSourceViewer() returns null so that calling getFindReplaceTarget() is pointless, return something meaningful. org.eclipse.ui.texteditor.FindReplaceTarget is doing the same. Change-Id: I36edbcfdcdcad7946c79909a0e2b6612450e85a1 Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
-rw-r--r--bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java19
1 files changed, 13 insertions, 6 deletions
diff --git a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
index 74b04591a..f3c1eaa1d 100644
--- a/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
+++ b/bundles/org.eclipse.compare/compare/org/eclipse/compare/contentmergeviewer/TextMergeViewer.java
@@ -26,6 +26,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Optional;
import java.util.ResourceBundle;
import org.eclipse.compare.CompareConfiguration;
@@ -1292,31 +1293,36 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
@Override
public int findAndSelect(int widgetOffset, String findString,
boolean searchForward, boolean caseSensitive, boolean wholeWord) {
- return getTarget().findAndSelect(widgetOffset, findString, searchForward, caseSensitive, wholeWord);
+ return Optional.ofNullable(getTarget()).map(
+ target -> target.findAndSelect(widgetOffset, findString, searchForward, caseSensitive, wholeWord))
+ .orElse(-1);
}
private IFindReplaceTarget getTarget() {
- return fFocusPart.getSourceViewer().getFindReplaceTarget();
+ return Optional.ofNullable(fFocusPart).map(MergeSourceViewer::getSourceViewer)
+ .map(SourceViewer::getFindReplaceTarget)
+ .orElse(null);
}
@Override
public Point getSelection() {
- return getTarget().getSelection();
+ return Optional.ofNullable(getTarget()).map(target -> target.getSelection())
+ .orElse(new Point(-1, -1));
}
@Override
public String getSelectionText() {
- return getTarget().getSelectionText();
+ return Optional.ofNullable(getTarget()).map(IFindReplaceTarget::getSelectionText).orElse(""); //$NON-NLS-1$
}
@Override
public boolean isEditable() {
- return getTarget().isEditable();
+ return Optional.ofNullable(getTarget()).map(IFindReplaceTarget::isEditable).orElse(false);
}
@Override
public void replaceSelection(String text) {
- getTarget().replaceSelection(text);
+ Optional.ofNullable(getTarget()).ifPresent(target -> target.replaceSelection(text));
}
@Override
@@ -1351,6 +1357,7 @@ public class TextMergeViewer extends ContentMergeViewer implements IAdaptable {
if (findReplaceTarget instanceof IFindReplaceTargetExtension2) {
return ((IFindReplaceTargetExtension2) findReplaceTarget).validateTargetState();
}
+ // TODO not sure if true when findReplaceTarget is null
return true;
}

Back to the top