From 27dfdd571bd2f7bd219eb0ac1ce7ba8836a15f67 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 --- .../jclouds/domain/internal/ResourceMetadataImpl.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 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 2816abfaf6..e5258faecd 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.net.URI; import java.util.Map; @@ -62,10 +64,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(); } /**