diff --git a/gson/src/main/java/com/google/gson/internal/bind/JsonTreeReader.java b/gson/src/main/java/com/google/gson/internal/bind/JsonTreeReader.java index ac6593350e..0954fb332b 100644 --- a/gson/src/main/java/com/google/gson/internal/bind/JsonTreeReader.java +++ b/gson/src/main/java/com/google/gson/internal/bind/JsonTreeReader.java @@ -308,11 +308,11 @@ private void push(Object newTop) { StringBuilder result = new StringBuilder().append('$'); for (int i = 0; i < stackSize; i++) { if (stack[i] instanceof JsonArray) { - if (stack[++i] instanceof Iterator) { + if (++i < stackSize && stack[i] instanceof Iterator) { result.append('[').append(pathIndices[i]).append(']'); } } else if (stack[i] instanceof JsonObject) { - if (stack[++i] instanceof Iterator) { + if (++i < stackSize && stack[i] instanceof Iterator) { result.append('.'); if (pathNames[i] != null) { result.append(pathNames[i]);