@@ -398,7 +398,7 @@ private List<Object> parseTabularArray(String header, int depth, String arrayDel
398398 * Returns true if parsing should continue, false if array should terminate.
399399 */
400400 private boolean processTabularArrayLine (int depth , List <String > keys , String arrayDelimiter ,
401- List <Object > result ) {
401+ List <Object > result ) {
402402 String line = lines [currentLine ];
403403
404404 if (isBlankLine (line )) {
@@ -483,7 +483,7 @@ private boolean shouldTerminateTabularArray(String line, int lineDepth, int dept
483483 * false otherwise.
484484 */
485485 private boolean processTabularRow (String line , int lineDepth , int depth , List <String > keys ,
486- String arrayDelimiter , List <Object > result ) {
486+ String arrayDelimiter , List <Object > result ) {
487487 if (lineDepth == depth + 1 ) {
488488 String rowContent = line .substring ((depth + 1 ) * options .indent ());
489489 Map <String , Object > row = parseTabularRow (rowContent , keys , arrayDelimiter );
@@ -655,9 +655,17 @@ private Object parseListItem(String content, int depth) {
655655 String key = StringEscaper .unescape (itemContent .substring (0 , colonIdx ).trim ());
656656 String value = itemContent .substring (colonIdx + 1 ).trim ();
657657
658+ currentLine ++;
659+
658660 Map <String , Object > item = new LinkedHashMap <>();
659- // List item is at depth + 1, so pass depth + 1 to parseObjectItemValue
660- Object parsedValue = parseObjectItemValue (value , depth + 1 );
661+ Object parsedValue ;
662+ // If no next line exists, handle simple case
663+ if (currentLine >= lines .length ) {
664+ parsedValue = value .trim ().isEmpty () ? new LinkedHashMap <>() : PrimitiveDecoder .parse (value );
665+ } else {
666+ // List item is at depth + 1, so pass depth + 1 to parseObjectItemValue
667+ parsedValue = parseObjectItemValue (value , depth + 1 );
668+ }
661669 item .put (key , parsedValue );
662670 parseListItemFields (item , depth );
663671
@@ -668,20 +676,14 @@ private Object parseListItem(String content, int depth) {
668676 * Parses the value portion of an object item in a list, handling nested
669677 * objects,
670678 * empty values, and primitives.
671- *
679+ *
672680 * @param value the value string to parse
673681 * @param depth the depth of the list item
674682 * @return the parsed value (Map, List, or primitive)
675683 */
676684 private Object parseObjectItemValue (String value , int depth ) {
677- currentLine ++;
678685 boolean isEmpty = value .trim ().isEmpty ();
679686
680- // If no next line exists, handle simple case
681- if (currentLine >= lines .length ) {
682- return isEmpty ? new LinkedHashMap <>() : PrimitiveDecoder .parse (value );
683- }
684-
685687 // Find next non-blank line and its depth
686688 Integer nextDepth = findNextNonBlankLineDepth ();
687689 if (nextDepth == null ) {
@@ -703,7 +705,7 @@ private Object parseObjectItemValue(String value, int depth) {
703705
704706 /**
705707 * Finds the depth of the next non-blank line, skipping blank lines.
706- *
708+ *
707709 * @return the depth of the next non-blank line, or null if none exists
708710 */
709711 private Integer findNextNonBlankLineDepth () {
@@ -721,7 +723,7 @@ private Integer findNextNonBlankLineDepth() {
721723
722724 /**
723725 * Parses a field value, handling nested objects, empty values, and primitives.
724- *
726+ *
725727 * @param fieldValue the value string to parse
726728 * @param fieldDepth the depth at which the field is located
727729 * @return the parsed value (Map, List, or primitive)
@@ -758,7 +760,7 @@ private Object parseFieldValue(String fieldValue, int fieldDepth) {
758760
759761 /**
760762 * Parses a keyed array field and adds it to the item map.
761- *
763+ *
762764 * @param fieldContent the field content to parse
763765 * @param item the map to add the field to
764766 * @param depth the depth of the list item
@@ -791,7 +793,7 @@ private boolean parseKeyedArrayField(String fieldContent, Map<String, Object> it
791793
792794 /**
793795 * Parses a key-value field and adds it to the item map.
794- *
796+ *
795797 * @param fieldContent the field content to parse
796798 * @param item the map to add the field to
797799 * @param depth the depth of the list item
@@ -1107,7 +1109,7 @@ private void processDirectChildLine(Map<String, Object> result, String line, int
11071109 * Processes a keyed array line (e.g., "key[3]: value").
11081110 */
11091111 private void processKeyedArrayLine (Map <String , Object > result , String content , Matcher keyedArray ,
1110- int parentDepth ) {
1112+ int parentDepth ) {
11111113 String originalKey = keyedArray .group (1 ).trim ();
11121114 String key = StringEscaper .unescape (originalKey );
11131115 String arrayHeader = content .substring (keyedArray .group (1 ).length ());
@@ -1238,7 +1240,7 @@ private void checkFinalValueConflict(String finalSegment, Object existing, Objec
12381240 /**
12391241 * Parses a key-value string into an Object, handling nested objects, empty
12401242 * values, and primitives.
1241- *
1243+ *
12421244 * @param value the value string to parse
12431245 * @param depth the depth at which the key-value pair is located
12441246 * @return the parsed value (Map, List, or primitive)
@@ -1277,15 +1279,15 @@ private Object parseKeyValue(String value, int depth) {
12771279
12781280 /**
12791281 * Puts a key-value pair into a map, handling path expansion.
1280- *
1282+ *
12811283 * @param map the map to put the key-value pair into
12821284 * @param originalKey the original key before being unescaped (used for path
12831285 * expansion check)
12841286 * @param unescapedKey the unescaped key
12851287 * @param value the value to put
12861288 */
12871289 private void putKeyValueIntoMap (Map <String , Object > map , String originalKey , String unescapedKey ,
1288- Object value ) {
1290+ Object value ) {
12891291 // Handle path expansion
12901292 if (shouldExpandKey (originalKey )) {
12911293 expandPathIntoMap (map , unescapedKey , value );
@@ -1439,4 +1441,4 @@ private void validateIndentation(String line) {
14391441 }
14401442 }
14411443 }
1442- }
1444+ }
0 commit comments