Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLaurent Delaigue2016-01-11 14:17:25 +0000
committerLaurent Delaigue2016-02-02 16:38:13 +0000
commita6b0693d96f4cd424c8b531f04421393ed1947b4 (patch)
treef25342ddff603844f0c49fa276af61ff13536b95
parenteee88a22481f8ba5d532a6ea3063c1fa0db478b4 (diff)
downloadorg.eclipse.emf.compare-a6b0693d96f4cd424c8b531f04421393ed1947b4.tar.gz
org.eclipse.emf.compare-a6b0693d96f4cd424c8b531f04421393ed1947b4.tar.xz
org.eclipse.emf.compare-a6b0693d96f4cd424c8b531f04421393ed1947b4.zip
[485513] Fix NPE in NameMatchingStrategy.findMatch
Bug: 485513 Change-Id: I1a10e9e5f5d5a9304673f49c270243499688e0a9 Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
-rw-r--r--plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/NameMatchingStrategy.java27
1 files changed, 25 insertions, 2 deletions
diff --git a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/NameMatchingStrategy.java b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/NameMatchingStrategy.java
index d61fd01d3..5615eea85 100644
--- a/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/NameMatchingStrategy.java
+++ b/plugins/org.eclipse.emf.compare/src/org/eclipse/emf/compare/match/resource/NameMatchingStrategy.java
@@ -79,8 +79,7 @@ public class NameMatchingStrategy implements IResourceMatchingStrategy {
protected Resource findMatch(Resource reference, Iterable<Resource> candidates) {
final URI referenceURI = reference.getURI();
for (Resource candidate : candidates) {
- if (referenceURI == candidate.getURI() || referenceURI != null && candidate.getURI() != null
- && referenceURI.lastSegment().equals(candidate.getURI().lastSegment())) {
+ if (urisLastSegmentMatch(referenceURI, candidate.getURI())) {
return candidate;
}
}
@@ -88,6 +87,30 @@ public class NameMatchingStrategy implements IResourceMatchingStrategy {
}
/**
+ * Indicates whether the given URIs are equal or have the same last segment.
+ *
+ * @param referenceURI
+ * Reference URI
+ * @param otherURI
+ * Candidate URI
+ * @return <code>true</code> if both URIs are null, or if they are equal, or if they have the same
+ * non-null last segment.
+ */
+ private boolean urisLastSegmentMatch(URI referenceURI, URI otherURI) {
+ if (referenceURI == otherURI) {
+ return true;
+ }
+ if (referenceURI != null && otherURI != null) {
+ if (referenceURI.equals(otherURI)) {
+ return true;
+ }
+ String lastSegment = referenceURI.lastSegment();
+ return lastSegment != null && lastSegment.equals(otherURI.lastSegment());
+ }
+ return false;
+ }
+
+ /**
* Creates a {@link MatchResource} instance and sets all three resources of the mapping on it.
*
* @param left

Back to the top