SLING-9742 - PubQueue#getEntry throws when provided an illegal arguments
diff --git a/src/main/java/org/apache/sling/distribution/journal/queue/impl/EntryUtil.java b/src/main/java/org/apache/sling/distribution/journal/queue/impl/EntryUtil.java
index 9b9a84b..50b9884 100644
--- a/src/main/java/org/apache/sling/distribution/journal/queue/impl/EntryUtil.java
+++ b/src/main/java/org/apache/sling/distribution/journal/queue/impl/EntryUtil.java
@@ -18,6 +18,8 @@
*/
package org.apache.sling.distribution.journal.queue.impl;
+import javax.annotation.Nonnull;
+
import org.apache.sling.distribution.journal.queue.QueueItemFactory;
import org.apache.sling.distribution.queue.DistributionQueueItem;
@@ -26,7 +28,7 @@
private EntryUtil() {
}
- public static long entryOffset(String entryId) {
+ public static long entryOffset(@Nonnull String entryId) {
String[] chunks = entryId.split("@");
if (chunks.length != 2) {
throw new IllegalArgumentException(String.format("Unsupported entryId format %s", entryId));
diff --git a/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubErrQueue.java b/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubErrQueue.java
index 69f1f59..790acae 100644
--- a/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubErrQueue.java
+++ b/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubErrQueue.java
@@ -96,10 +96,12 @@
@Override
public DistributionQueueEntry getEntry(@Nonnull String entryId) {
- DistributionQueueItem queueItem = agentQueue.getItem(EntryUtil.entryOffset(entryId));
- return (queueItem != null)
- ? entryFactory.create(queueItem)
- : null;
+ try {
+ DistributionQueueItem queueItem = agentQueue.getItem(EntryUtil.entryOffset(entryId));
+ return (queueItem != null) ? entryFactory.create(queueItem) : null;
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
}
@Override
diff --git a/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueue.java b/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueue.java
index 3ca97fc..f8ed0ff 100644
--- a/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueue.java
+++ b/src/main/java/org/apache/sling/distribution/journal/queue/impl/PubQueue.java
@@ -124,8 +124,12 @@
@Override
public DistributionQueueEntry getEntry(String entryId) {
- DistributionQueueItem queueItem = offsetQueue.getItem(EntryUtil.entryOffset(entryId));
- return entryFactory.create(queueItem);
+ try {
+ DistributionQueueItem queueItem = offsetQueue.getItem(EntryUtil.entryOffset(entryId));
+ return entryFactory.create(queueItem);
+ } catch (IllegalArgumentException e) {
+ return null;
+ }
}
@Override
diff --git a/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueTest.java b/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueTest.java
index 8ae13b4..e540502 100644
--- a/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueTest.java
+++ b/src/test/java/org/apache/sling/distribution/journal/queue/impl/PubQueueTest.java
@@ -103,6 +103,12 @@
}
@Test
+ public void testGetItemWithIllegalArgument() {
+ assertNull(queue.getEntry("illegal"));
+ assertNull(queue.getEntry("illegal@argument"));
+ }
+
+ @Test
public void testGetItem() throws Exception {
addEntries();