Skip to content

AddKeyValue logging parser errors for valid json files #6207

@daraghhiggins12

Description

@daraghhiggins12

What version of OpenRewrite are you using?

  • OpenRewrite v8.64.0
  • Maven/Gradle plugin v6.22.1

Description

Running the AddKeyValue recipe for a valid JSON file prints parser error:

line 1:2 mismatched input '<EOF>' expecting {'[', '*', Identifier, StringLiteral}

How are you running OpenRewrite?

I am using the Maven plugin, and my project is a single module project.

<plugin>
  <groupId>org.openrewrite.maven</groupId>
  <artifactId>rewrite-maven-plugin</artifactId>
  <version>6.22.1</version>
  <configuration>
    ... 
  </configuration>
</plugin>

What is the smallest, simplest way to reproduce the problem?

rewrite.yml

---
type: specs.openrewrite.org/v1beta/recipe
name: sampleJsonAddKey
displayName: JSON Sample
recipeList:
  - org.openrewrite.json.AddKeyValue:
      keyPath: "$."
      key: "surname"
      value: "\"Doe\""

When running the above recipe using mvn rewrite:run against the following json:

{
  "name": "John"
}

the key surname is correctly added to the JSON with the intended value but parsing errors are printed

[INFO] Running recipe(s)...
line 1:2 mismatched input '<EOF>' expecting {'[', '*', Identifier, StringLiteral}
[WARNING] Changes have been made to pre.json by:
[WARNING]     org.openrewrite.json.AddKeyValue: {keyPath=$., key=surname, value="Doe", prepend=false}
[WARNING] Please review and commit the results.
[WARNING] Estimate time saved: 5m

Even when filtering to only valid JSON files using FindSourceFiles the parser error stills prints

---
type: specs.openrewrite.org/v1beta/recipe
name: sampleJsonAddKey
displayName: JSON Sample
preconditions:
  - org.openrewrite.FindSourceFiles:
      filePattern: "**/*.json"
recipeList:
  - org.openrewrite.json.AddKeyValue:
      keyPath: "$."
      key: "surname"
      value: "\"Doe\""

What did you expect to see?

No parsing errors for valid JSON files

What did you see instead?

Parsing errors printed for valid JSON files

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions