aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMalgorzata Janczarska2011-10-21 13:12:11 (EDT)
committerTomasz Zarna2011-10-21 13:12:11 (EDT)
commit72e049524fb42f6dcc2f3d8af5c27231b8089c37 (patch)
treececa59a44f9e2c4b4df0e8c1fd67c59d5c0ad9dc
parent33f3884b44162a4fc6b1236e969d2804dcd07c28 (diff)
downloadeclipse.platform.team-72e049524fb42f6dcc2f3d8af5c27231b8089c37.zip
eclipse.platform.team-72e049524fb42f6dcc2f3d8af5c27231b8089c37.tar.gz
eclipse.platform.team-72e049524fb42f6dcc2f3d8af5c27231b8089c37.tar.bz2
bug 347557: [Edit] NPE when saving a file in a compare editor (always)I20111024-1300
A fix for the case founded by Dani when one part of the comparison is empty e.g. after adding a new file.
-rw-r--r--bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java9
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java52
2 files changed, 57 insertions, 4 deletions
diff --git a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java
index fb839b4..afa44be 100644
--- a/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java
+++ b/bundles/org.eclipse.team.ui/src/org/eclipse/team/internal/ui/synchronize/LocalResourceSaveableComparison.java
@@ -248,10 +248,10 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison
*/
public String getName() {
// Return the name of the file element as held in the compare input
- if (input.getLeft().equals(fileElement)) {
+ if (input.getLeft() != null && input.getLeft().equals(fileElement)) {
return input.getLeft().getName();
}
- if (input.getRight().equals(fileElement)) {
+ if (input.getRight() != null && input.getRight().equals(fileElement)) {
return input.getRight().getName();
}
// Fallback call returning name of the main non-null element of the input
@@ -289,14 +289,15 @@ public abstract class LocalResourceSaveableComparison extends SaveableComparison
ContentMergeViewer cmv = (ContentMergeViewer) e.getSource();
- if (input.getLeft().equals(fileElement)) {
+ if (input.getLeft() != null && input.getLeft().equals(fileElement)) {
if (changed && cmv.internalIsLeftDirty())
setDirty(changed);
else if (!changed && !cmv.internalIsLeftDirty()) {
setDirty(changed);
}
}
- if (input.getRight().equals(fileElement)) {
+ if (input.getRight() != null
+ && input.getRight().equals(fileElement)) {
if (changed && cmv.internalIsRightDirty())
setDirty(changed);
else if (!changed && !cmv.internalIsRightDirty()) {
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java
index f8d1add..bd53f5b 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ui/SaveableCompareEditorInputTest.java
@@ -272,4 +272,56 @@ public class SaveableCompareEditorInputTest extends TeamTest {
* handled, see javadoc to SaveableCompareEditorInput.
*/
}
+
+ public void testDirtyFlagOnLocalResourceTypedElementAndEmptyRight()
+ throws CoreException, InvocationTargetException,
+ InterruptedException, IllegalArgumentException, SecurityException,
+ IllegalAccessException, NoSuchFieldException,
+ NoSuchMethodException, IOException {
+
+ // Create left element by SaveableCompareEditorInput to be properly
+ // saved, see javadoc to SaveableCompareEditorInput
+ LocalResourceTypedElement el1 = (LocalResourceTypedElement) SaveableCompareEditorInput
+ .createFileElement(file1);
+ ITypedElement el2 = null;
+
+ CompareConfiguration conf = new CompareConfiguration();
+ conf.setLeftEditable(true);
+ TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(
+ el1, el2, conf);
+
+ compareEditorInput.prepareCompareInput(null);
+
+ verifyDirtyStateChanges(compareEditorInput);
+
+ // check whether file was saved
+
+ assertTrue(compareContent(new ByteArrayInputStream(
+ (fileContents1 + appendFileContents).getBytes()),
+ file1.getContents()));
+ }
+
+ public void testDirtyFlagOnCustomTypedElementAndEmptyRight()
+ throws CoreException, InvocationTargetException,
+ InterruptedException, IllegalArgumentException, SecurityException,
+ IllegalAccessException, NoSuchFieldException,
+ NoSuchMethodException, IOException {
+
+ ITypedElement el1 = new TestFileElement(file1);
+ ITypedElement el2 = null;
+
+ CompareConfiguration conf = new CompareConfiguration();
+ conf.setLeftEditable(true);
+ TestSaveableEditorInput compareEditorInput = new TestSaveableEditorInput(
+ el1, el2, conf);
+
+ compareEditorInput.prepareCompareInput(null);
+
+ verifyDirtyStateChanges(compareEditorInput);
+
+ /*
+ * not checking if changes were saved because in this case saving is not
+ * handled, see javadoc to SaveableCompareEditorInput.
+ */
+ }
}