From 1a63bb58e20ec965a7281fdee59363221ee11f99 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Fri, 3 Aug 2012 08:31:09 +0200 Subject: [PATCH] fix npe on empty repository --- .../scm/repository/spi/HgTagsCommand.java | 56 ++++++++++++++++--- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgTagsCommand.java b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgTagsCommand.java index 3adbb1a4fd..353ff7a7b4 100644 --- a/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgTagsCommand.java +++ b/scm-plugins/scm-hg-plugin/src/main/java/sonia/scm/repository/spi/HgTagsCommand.java @@ -30,15 +30,18 @@ */ + package sonia.scm.repository.spi; //~--- non-JDK imports -------------------------------------------------------- import com.google.common.base.Function; +import com.google.common.base.Strings; import com.google.common.collect.Lists; import sonia.scm.repository.Repository; import sonia.scm.repository.Tag; +import sonia.scm.util.Util; //~--- JDK imports ------------------------------------------------------------ @@ -79,16 +82,55 @@ public class HgTagsCommand extends AbstractCommand implements TagsCommand List tagList = cmd.includeTip().execute(); - return Lists.transform(tagList, - new Function() - { + List tags = null; - @Override - public Tag apply(com.aragost.javahg.commands.Tag f) + // check for empty repository + if (Util.isNotEmpty(tagList) && tagList.get(0).getChangeset() != null) + { + tags = Lists.transform(tagList, new TagTransformer()); + } + + if (tags == null) + { + tags = Lists.newArrayList(); + } + + return tags; + } + + //~--- inner classes -------------------------------------------------------- + + /** + * Class description + * + * + * @version Enter version here..., 12/08/03 + * @author Enter your name here... + */ + private static class TagTransformer + implements Function + { + + /** + * Method description + * + * + * @param f + * + * @return + */ + @Override + public Tag apply(com.aragost.javahg.commands.Tag f) + { + Tag t = null; + + if ((f != null) &&!Strings.isNullOrEmpty(f.getName()) + && (f.getChangeset() != null)) { - return new Tag(f.getName(), f.getChangeset().getNode()); + t = new Tag(f.getName(), f.getChangeset().getNode()); } - }); + return t; + } } }