- if ((source.getBuckets() != null) && (source.getBuckets().getBucket().size() != 0)) {
-
- Collections.sort(source.getBuckets().getBucket(), COMPARATOR);
-
- List<BucketsList> bucketLists = salToOFBucketList(source.getBuckets(), data.getVersion(), source.getGroupType().getIntValue(), data.getDatapathId());
- groupModInputBuilder.setBucketsList(bucketLists);
+ final Buckets buckets = source.getBuckets();
+ if (buckets != null) {
+ final Map<BucketKey, Bucket> bucket = buckets.nonnullBucket();
+ if (!bucket.isEmpty()) {
+ // TODO: we should be able to just sort the resulting the resulting list and not go through
+ // two copies
+ List<Bucket> bucketList = new ArrayList<>(bucket.values());
+ Collections.sort(bucketList, COMPARATOR);
+ List<BucketsList> bucketLists = salToOFBucketList(bucketList, data.getVersion(),
+ source.getGroupType().getIntValue(), data.getDatapathId());
+ groupModInputBuilder.setBucketsList(bucketLists);
+ }