diff --git a/rewrite-json/src/main/java/org/openrewrite/json/internal/JsonParserVisitor.java b/rewrite-json/src/main/java/org/openrewrite/json/internal/JsonParserVisitor.java index 8a3e2f7b941..beb5909799b 100644 --- a/rewrite-json/src/main/java/org/openrewrite/json/internal/JsonParserVisitor.java +++ b/rewrite-json/src/main/java/org/openrewrite/json/internal/JsonParserVisitor.java @@ -332,20 +332,19 @@ private int positionOfNext(String untilDelim, @Nullable Character stop) { inSingleLineComment = false; } } else { - if (source.length() - untilDelim.length() > delimIndex + 1) { - switch (source.substring(delimIndex, delimIndex + 2)) { - case "//": - inSingleLineComment = true; - delimIndex++; - break; - case "/*": - inMultiLineComment = true; - delimIndex++; - break; - case "*/": - inMultiLineComment = false; - delimIndex = delimIndex + 2; - break; + if (inMultiLineComment) { + if (source.charAt(delimIndex) == '*' && source.charAt(delimIndex + 1) == '/') { + inMultiLineComment = false; + delimIndex += 2; + } + } else if (source.charAt(delimIndex) == '/' && source.length() - untilDelim.length() > delimIndex + 1) { + int next = source.charAt(delimIndex + 1); + if (next == '/') { + inSingleLineComment = true; + delimIndex++; + } else if (next == '*') { + inMultiLineComment = true; + delimIndex++; } }