diff options
author | Laurent Delaigue | 2016-01-11 14:17:25 +0000 |
---|---|---|
committer | Laurent Delaigue | 2016-02-02 16:38:13 +0000 |
commit | a6b0693d96f4cd424c8b531f04421393ed1947b4 (patch) | |
tree | f25342ddff603844f0c49fa276af61ff13536b95 | |
parent | eee88a22481f8ba5d532a6ea3063c1fa0db478b4 (diff) | |
download | org.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.java | 27 |
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 |