You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@daffodil.apache.org by GitBox <gi...@apache.org> on 2019/04/26 14:58:36 UTC

[GitHub] [incubator-daffodil] jadams-tresys commented on a change in pull request #212: Catch error when delimiter expression fails

jadams-tresys commented on a change in pull request #212: Catch error when delimiter expression fails
URL: https://github.com/apache/incubator-daffodil/pull/212#discussion_r278985917
 
 

 ##########
 File path: daffodil-runtime1/src/main/scala/org/apache/daffodil/processors/parsers/ElementKindParsers.scala
 ##########
 @@ -57,26 +57,28 @@ class DelimiterStackParser(
     val newLocalIndex = start.mpstate.delimiters.length
     start.mpstate.delimitersLocalIndexStack.push(newLocalIndex)
 
-    // evaluate and add delimiters to the stack
-    var i: Int = 0
-    while (i < delimiters.length) {
-      start.mpstate.delimiters ++= delimiters(i).evaluate(start)
-      i += 1
-    }
-
-    // set the index of the newly added delimiters
-    val newDelimLen = start.mpstate.delimiters.length
-    i = newLocalIndex
-    while (i < newDelimLen) {
-      start.mpstate.delimiters(i).indexInDelimiterStack = i
-      i += 1
-    }
+    try {
+      // evaluate and add delimiters to the stack
+      var i: Int = 0
+      while (i < delimiters.length) {
+        start.mpstate.delimiters ++= delimiters(i).evaluate(start)
+        i += 1
+      }
 
-    // parse
-    bodyParser.parse1(start)
+      // set the index of the newly added delimiters
+      val newDelimLen = start.mpstate.delimiters.length
+      i = newLocalIndex
+      while (i < newDelimLen) {
+        start.mpstate.delimiters(i).indexInDelimiterStack = i
+        i += 1
+      }
 
-    // pop delimiters
-    start.mpstate.delimiters.reduceToSize(start.mpstate.delimitersLocalIndexStack.pop)
+      // parse
+        bodyParser.parse1(start)
+    } finally {
+      // pop delimiters
+      start.mpstate.delimiters.reduceToSize(start.mpstate.delimitersLocalIndexStack.pop)
+    }
 
 Review comment:
   So I added a small fix to change it to an SDE.  As far as I can tell form the code, the only thing that will generate an IllegalArgumentException in DPath is the StringToNonEmptyString object, which is exactly where we want to create the SDE.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services