sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tma...@apache.org
Subject [sling-org-apache-sling-distribution-journal] branch master updated: SLING-9742 - PubQueue#getEntry throws when provided an illegal arguments
Date Fri, 25 Sep 2020 12:19:00 GMT
This is an automated email from the ASF dual-hosted git repository.

tmaret pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-distribution-journal.git


The following commit(s) were added to refs/heads/master by this push:
     new 0284693  SLING-9742 - PubQueue#getEntry throws when provided an illegal arguments
0284693 is described below

commit 02846937fa0e07d183f50484bc68e028337c3fe5
Author: tmaret <tmaret@adobe.com>
AuthorDate: Fri Sep 25 14:18:39 2020 +0200

    SLING-9742 - PubQueue#getEntry throws when provided an illegal arguments
---
 .../sling/distribution/journal/queue/impl/EntryUtil.java       |  4 +++-
 .../sling/distribution/journal/queue/impl/PubErrQueue.java     | 10 ++++++----
 .../apache/sling/distribution/journal/queue/impl/PubQueue.java |  8 ++++++--
 .../sling/distribution/journal/queue/impl/PubQueueTest.java    |  6 ++++++
 4 files changed, 21 insertions(+), 7 deletions(-)

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 @@ public final class EntryUtil {
     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 @@ public class PubErrQueue implements DistributionQueue {
 
     @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 @@ public class PubQueue implements DistributionQueue {
 
     @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 @@ public class PubQueueTest {
     }
 
     @Test
+    public void testGetItemWithIllegalArgument() {
+        assertNull(queue.getEntry("illegal"));
+        assertNull(queue.getEntry("illegal@argument"));
+    }
+
+    @Test
     public void testGetItem() throws Exception {
         addEntries();
         


Mime
View raw message