diff --git a/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java b/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java index 5185121e89..891cce8be0 100644 --- a/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java +++ b/source/java/org/alfresco/repo/tagging/TaggingServiceImpl.java @@ -1188,14 +1188,41 @@ public class TaggingServiceImpl implements TaggingService, while (nextLine != null) { String[] values = nextLine.split("\\" + TAG_DETAILS_DELIMITER); - result.add(new TagDetailsImpl(values[0], Integer.parseInt(values[1]))); + if(values.length == 1) + { + if(logger.isDebugEnabled()) + { + logger.debug("No count for tag "+values[0]); + } + } + else if (values.length > 1) + { + try + { + result.add(new TagDetailsImpl(values[0], Integer.parseInt(values[1]))); + if(values.length > 2) + { + if(logger.isDebugEnabled()) + { + logger.debug("Ignoring extra guff for tag: " + values[0]); + } + } + } + catch(NumberFormatException nfe) + { + if(logger.isDebugEnabled()) + { + logger.debug("Invalid tag count for " + values[0] + "<"+values[1]+">"); + } + } + } nextLine = reader.readLine(); } } - catch (IOException exception) + catch (Exception exception) { - throw new AlfrescoRuntimeException("Unable to read tag details", exception); + logger.warn("Unable to read tag details", exception); } finally { diff --git a/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java b/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java index 5908f475be..ec9c046cb6 100644 --- a/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java +++ b/source/test-java/org/alfresco/repo/tagging/TaggingServiceImplTest.java @@ -18,7 +18,9 @@ */ package org.alfresco.repo.tagging; +import java.io.ByteArrayInputStream; import java.io.Serializable; +import java.io.UnsupportedEncodingException; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; @@ -2121,4 +2123,16 @@ public class TaggingServiceImplTest extends TestCase } }); } + + public void testTagFileRead() throws UnsupportedEncodingException + { + List tags = TaggingServiceImpl.readTagDetails(new ByteArrayInputStream("Tag1|10\nTag2|20\nInvalid\nInvalid2|\nInvalid3|One\nTooMany|1|2\n\n".getBytes("UTF-8"))); + assertEquals(3, tags.size()); + assertEquals(tags.get(0).getName(), "Tag1"); + assertEquals(tags.get(1).getName(), "Tag2"); + assertEquals(tags.get(2).getName(), "TooMany"); + assertEquals(tags.get(0).getCount(), 10); + assertEquals(tags.get(1).getCount(), 20); + assertEquals(tags.get(2).getCount(), 1); + } }