diff options
author | Malgorzata Janczarska | 2011-10-21 17:12:11 +0000 |
---|---|---|
committer | Tomasz Zarna | 2011-10-21 17:12:11 +0000 |
commit | 72e049524fb42f6dcc2f3d8af5c27231b8089c37 (patch) | |
tree | ceca59a44f9e2c4b4df0e8c1fd67c59d5c0ad9dc | |
parent | 33f3884b44162a4fc6b1236e969d2804dcd07c28 (diff) | |
download | eclipse.platform.team-72e049524fb42f6dcc2f3d8af5c27231b8089c37.tar.gz eclipse.platform.team-72e049524fb42f6dcc2f3d8af5c27231b8089c37.tar.xz eclipse.platform.team-72e049524fb42f6dcc2f3d8af5c27231b8089c37.zip |
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.
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 fb839b445..afa44be74 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 f8d1add85..bd53f5bc9 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.
+ */
+ }
}
|