Prevent NPE from overriden Resource implementations
Some resource implementations fail to consider "null" input as the
options map for "doSave" and end up in NullPointerExceptions.
Change-Id: Ie38dff790ac4ed7b1763fc5a8290f610216add8e
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/fallback/TextFallbackCompareInput.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/fallback/TextFallbackCompareInput.java
index c21453b..b0efa83 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/fallback/TextFallbackCompareInput.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/contentmergeviewer/fallback/TextFallbackCompareInput.java
@@ -16,6 +16,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.LinkedHashMap;
import java.util.List;
import org.eclipse.compare.ITypedElement;
@@ -34,8 +35,8 @@
import org.eclipse.team.internal.ui.synchronize.LocalResourceTypedElement;
/**
- * A highly specialized implementation of a compare input that uses {@link TextFallbackCompareInputData text input
- * data} to manage the information about the ancestor, left, and right.
+ * A highly specialized implementation of a compare input that uses {@link TextFallbackCompareInputData text
+ * input data} to manage the information about the ancestor, left, and right.
*/
@SuppressWarnings("restriction")
public final class TextFallbackCompareInput extends AbstractCompareInput {
@@ -88,10 +89,14 @@
* @param showPreview
* whether this is input for preview mode.
*/
- public TextFallbackCompareInput(int kind, TextFallbackCompareInputData textInputData, boolean showPreview) {
- super(kind, getElement(textInputData.getOriginTypedElement(), textInputData.getOriginResource(), showPreview),
+ public TextFallbackCompareInput(int kind, TextFallbackCompareInputData textInputData,
+ boolean showPreview) {
+ super(kind,
+ getElement(textInputData.getOriginTypedElement(), textInputData.getOriginResource(),
+ showPreview),
getElement(textInputData.getLeftTypedElement(), textInputData.getLeftResource(), showPreview),
- getElement(textInputData.getRightTypedElement(), textInputData.getRightResource(), showPreview));
+ getElement(textInputData.getRightTypedElement(), textInputData.getRightResource(),
+ showPreview));
this.textInputData = textInputData;
}
@@ -198,7 +203,7 @@
public InputStream getContents() throws CoreException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
try {
- xmlResource.save(byteArrayOutputStream, null);
+ xmlResource.save(byteArrayOutputStream, new LinkedHashMap<>());
} catch (IOException e) {
EMFCompareIDEUIPlugin.getDefault().log(e);
}
diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceStreamAccessorImpl.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceStreamAccessorImpl.java
index e0fa18f..747cc4a 100644
--- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceStreamAccessorImpl.java
+++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/contentmergeviewer/accessor/impl/ResourceStreamAccessorImpl.java
@@ -15,6 +15,7 @@
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.LinkedHashMap;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.emf.common.notify.AdapterFactory;
@@ -89,7 +90,7 @@
public InputStream getContents() throws CoreException {
ByteArrayOutputStream os = new ByteArrayOutputStream(INPUT_STREAM_DEFAULT_SIZE);
try {
- fResource.save(os, null);
+ fResource.save(os, new LinkedHashMap<>());
} catch (IOException e) {
EMFCompareRCPUIPlugin.getDefault().log(e);
}