diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java b/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java index f07a57f5..e6b73385 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/PathCompiler.java @@ -63,13 +63,13 @@ public class PathCompiler { LinkedList filterList = new LinkedList(asList(filters)); if (trimmedPath.charAt(0) != '$' && trimmedPath.charAt(0) != '@') { - trimmedPath = "$." + trimmedPath; + trimmedPath = Utils.concat("$.", trimmedPath); } boolean isRootPath = (trimmedPath.charAt(0) == '$'); if (trimmedPath.charAt(0) == '@') { - trimmedPath = "$" + trimmedPath.substring(1); + trimmedPath = Utils.concat("$", trimmedPath.substring(1)); } if (trimmedPath.length() > 1 && @@ -78,10 +78,10 @@ public class PathCompiler { throw new InvalidPathException("Invalid path " + trimmedPath); } - String cacheKey = trimmedPath + isRootPath + filterList.toString(); + String cacheKey = Utils.concat(trimmedPath, Boolean.toString(isRootPath), filterList.toString()); Path p = cache.get(cacheKey); if (p != null) { - if (logger.isDebugEnabled()) logger.debug("Using cached path: " + cacheKey); + if (logger.isDebugEnabled()) logger.debug("Using cached path: {}", cacheKey); return p; } @@ -123,7 +123,7 @@ public class PathCompiler { } else { assertValidFieldChars(trimmedPath, i, positions); - fragment = PROPERTY_OPEN + trimmedPath.substring(i, i + positions) + PROPERTY_CLOSE; + fragment = Utils.concat(PROPERTY_OPEN, trimmedPath.substring(i, i + positions), PROPERTY_CLOSE); } i += positions; } @@ -135,7 +135,7 @@ public class PathCompiler { default: positions = fastForward(trimmedPath, i); - fragment = PROPERTY_OPEN + trimmedPath.substring(i, i + positions) + PROPERTY_CLOSE; + fragment = Utils.concat(PROPERTY_OPEN, trimmedPath.substring(i, i + positions), PROPERTY_CLOSE); i += positions; break; } diff --git a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java index 720728a2..7a4e2e15 100644 --- a/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java +++ b/json-path/src/main/java/com/jayway/jsonpath/internal/token/PathToken.java @@ -40,7 +40,7 @@ public abstract class PathToken { if(properties.size() == 1) { String property = properties.get(0); - String evalPath = currentPath + "['" + property + "']"; + String evalPath = Utils.concat(currentPath, "['", property, "']"); Object propertyVal = readObjectProperty(property, model, ctx); if(propertyVal == JsonProvider.UNDEFINED){ if(isLeaf()) { @@ -115,7 +115,7 @@ public abstract class PathToken { void handleArrayIndex(int index, String currentPath, Object model, EvaluationContextImpl ctx) { - String evalPath = currentPath + "[" + index + "]"; + String evalPath = Utils.concat(currentPath, "[", String.valueOf(index), "]"); PathRef pathRef = ctx.forUpdate() ? PathRef.create(model, index) : PathRef.NO_OP; try { Object evalHit = ctx.jsonProvider().getArrayIndex(model, index);