From fd65cbf203b7975755e2378b235024085fbb49d7 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Tue, 4 Dec 2012 22:42:47 -0800 Subject: [PATCH] fix issue #607: NPE in compareTo method of ResourceMetadataImpl --- .../domain/internal/ResourceMetadataImpl.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java b/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java index 3040e18c7f..18880085bb 100644 --- a/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java +++ b/core/src/main/java/org/jclouds/domain/internal/ResourceMetadataImpl.java @@ -20,6 +20,8 @@ package org.jclouds.domain.internal; import static com.google.common.base.Objects.equal; import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.collect.ComparisonChain.start; +import static com.google.common.collect.Ordering.natural; import java.io.Serializable; import java.net.URI; @@ -66,10 +68,10 @@ public abstract class ResourceMetadataImpl> implements Resourc * {@inheritDoc} */ @Override - public int compareTo(ResourceMetadata o) { - if (getName() == null) - return -1; - return (this == o) ? 0 : getName().compareTo(o.getName()); + public int compareTo(ResourceMetadata that) { + return start() + .compare(this.getName(), that.getName(), natural().nullsLast()) + .result(); } /** @@ -138,4 +140,4 @@ public abstract class ResourceMetadataImpl> implements Resourc .add("name", name).add("location", location).add("uri", uri).add("userMetadata", userMetadata); } -} \ No newline at end of file +}