You are viewing a plain text version of this content. The canonical link for it is here.
Posted to oak-issues@jackrabbit.apache.org by "Thomas Mueller (Jira)" <ji...@apache.org> on 2020/12/08 14:41:00 UTC

[jira] [Commented] (OAK-9297) Lenient checkpoint parsing

    [ https://issues.apache.org/jira/browse/OAK-9297?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17245924#comment-17245924 ] 

Thomas Mueller commented on OAK-9297:
-------------------------------------

Proposed patch:
{noformat}
oak-store-document

svn diff
Index: src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java
===================================================================
--- src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java	(revision 1883308)
+++ src/main/java/org/apache/jackrabbit/oak/plugins/document/Checkpoints.java	(working copy)
@@ -278,7 +278,7 @@
         }
 
         static Info fromString(String info) {
-            long expiryTime;
+            long expiryTime = 0;
             RevisionVector rv = null;
             Map<String, String> map;
             if (info.startsWith("{")) {
@@ -285,19 +285,11 @@
                 map = Maps.newHashMap();
                 JsopReader reader = new JsopTokenizer(info);
                 reader.read('{');
-                String key = reader.readString();
-                if (!EXPIRES.equals(key)) {
-                    throw new IllegalArgumentException("First entry in the " +
-                            "checkpoint info must be the expires date: " + info);
-                }
-                reader.read(':');
-                expiryTime = Long.parseLong(reader.readString());
-                while (reader.matches(',')) {
-                    key = reader.readString();
+                do {
+                    String key = reader.readString();
                     reader.read(':');
                     String value = reader.readString();
-                    // second entry is potentially checkpoint revision vector
-                    if (rv == null && map.isEmpty() && REVISION_VECTOR.equals(key)) {
+                    if (REVISION_VECTOR.equals(key) && rv == null) {
                         // try to read checkpoint
                         try {
                             rv = RevisionVector.fromString(value);
@@ -305,10 +297,18 @@
                             // not a revision vector, read as regular info entry
                             map.put(key, value);
                         }
+                    } else if (EXPIRES.equals(key) && expiryTime == 0) {
+                        try {
+                            expiryTime = Long.parseLong(value);
+                        } catch (NumberFormatException e) {
+                            LOG.warn("Expiry time format error: " + info);
+                            // not a revision vector, read as regular info entry
+                            map.put(key, value);
+                        }
                     } else {
                         map.put(key, value);
                     }
-                }
+                } while (reader.matches(','));
                 reader.read('}');
                 reader.read(JsopReader.END);
             } else {
{noformat}

> Lenient checkpoint parsing
> --------------------------
>
>                 Key: OAK-9297
>                 URL: https://issues.apache.org/jira/browse/OAK-9297
>             Project: Jackrabbit Oak
>          Issue Type: Improvement
>          Components: documentmk
>            Reporter: Thomas Mueller
>            Priority: Major
>
> Right now DocumentMK checkpoint parsing is quite restrictive, e.g. the "expires" entry needs to be the first entry, and if it's not, parsing throws an exception.
> I think it would be nice if parsing is lenient.



--
This message was sent by Atlassian Jira
(v8.3.4#803005)