rewrite icon indicating copy to clipboard operation
rewrite copied to clipboard

Dependency POM parse failure: rewrite-maven-plugin not telling which file has the issue

Open edeweerd1A opened this issue 7 months ago • 2 comments

Opening the issue here, as as far I could analyze the issue seems to be with rewrite-maven.

What version of OpenRewrite are you using?

Version of rewrite-maven: 8.48.1 Version of rewrite-maven-plugin: 6.3.0 Version of maven: 3.9.9 Version of java: JDK 17.0.15

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.3.0</version>
        <dependencies>
          <dependency>
            <groupId>org.openrewrite</groupId>
            <artifactId>rewrite-maven</artifactId>
            <version>8.48.1</version>
          </dependency>
          <dependency>
            <groupId>org.openrewrite</groupId>
            <artifactId>rewrite-java</artifactId>
            <version>8.48.1</version>
          </dependency>
        </dependencies>
        <executions>
          <execution>
            <id>run</id>
            <phase>package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <activeRecipes>
                <recipe>org.openrewrite.java.format.AutoFormat</recipe>
              </activeRecipes>
            </configuration>
          </execution>
        </executions>
      </plugin>

I am not running any specific recipe, the issue is happening before any recipe is applied.

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

Reproducer provided:

  1. Unzip reproducer-openrewrite-maven-pom-parse-error.zip
  2. Run from root:
cd incorrect-pom-project
mvn clean install
cd dependent-project
mvn clean install  

What did you expect to see?

The path of the POM file that cannot be parsed in the standard output.

Adding --debug does not fix the issue.

What did you see instead?

The path is absent from the output.

What is the full stack trace of any errors you encountered?

reproducer-openrewrite-maven-pom-parse-error.log

Are you interested in contributing a fix to OpenRewrite?

Yes

edeweerd1A avatar Jun 04 '25 11:06 edeweerd1A

Thanks for the report @edeweerd1A ! My first suggestion here would be to use the aligned latest version, as we've both improved diagnostics, as well as resolved a couple of Maven specific problems already.

From the log you've shared it seems like we're failing somewhere deep int eh Jackson / ctc XML parser:

Caused by: com.ctc.wstx.exc.WstxParsingException: Illegal processing instruction target ("xml"); xml (case insensitive) is reserved by the specs.
 at [row,col {unknown-source}]: [2,5]
    at com.ctc.wstx.sr.StreamScanner.constructWfcException (StreamScanner.java:634)
    at com.ctc.wstx.sr.StreamScanner.throwParseError (StreamScanner.java:504)
    at com.ctc.wstx.sr.BasicStreamReader.readPIPrimary (BasicStreamReader.java:4020)
    at com.ctc.wstx.sr.BasicStreamReader.nextFromProlog (BasicStreamReader.java:2156)
    at com.ctc.wstx.sr.BasicStreamReader.next (BasicStreamReader.java:1180)
    at com.fasterxml.jackson.dataformat.xml.XmlFactory._initializeXmlReader (XmlFactory.java:739)
    at com.fasterxml.jackson.dataformat.xml.XmlFactory._createParser (XmlFactory.java:600)
    at com.fasterxml.jackson.dataformat.xml.XmlFactory._createParser (XmlFactory.java:30)
    at com.fasterxml.jackson.core.JsonFactory.createParser (JsonFactory.java:1273)
    at com.fasterxml.jackson.databind.ObjectMapper.readValue (ObjectMapper.java:3885)
    at org.openrewrite.maven.internal.RawPom.parse (RawPom.java:133)
    at org.openrewrite.maven.internal.MavenPomDownloader.download (MavenPomDownloader.java:589)

Previously when we saw such issues is was due to a failure to download pom files, with these troubleshooting steps available to you: https://docs.openrewrite.org/reference/faq#im-getting-failed-to-parse-or-resolve-the-maven-pom-file-or-one-of-its-dependencies-we-cannot-reliably-continue-without-this-information-when-running-openrewrite

Hope that helps already! Appreciate any help by trying newer version, and running those diagnostics.

timtebeek avatar Jun 04 '25 12:06 timtebeek

Just had a closer look at this; thanks again! So traditionally our approach has been not to put the details in in the exception message (there's limited formatting options there), but instead to make the failure available through a marker on the source file, which can then be exported.

If you run the following command on your project

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=org.openrewrite.FindParseFailures -Drewrite.exportDatatables=true

Then you should see a org.openrewrite.table.ParseFailures data table produced in target/ listing the source path, exception type and full stacktrace. As per https://docs.openrewrite.org/recipes/core/findparsefailures and documented on https://docs.openrewrite.org/reference/faq#my-recipe-runs-but-is-not-making-any-changes-whats-happening

It could also be that a particular file is not parsed correctly. In such cases you'll see log line output which files failed to parse. You can use the Find source files with ParseExceptionResult markers diagnostic recipe to find & report these issues. Note that this again produces a data table for you to inspect.

Can you confirm that indeed already gives you the details you'd have needed to troubleshoot without making any changes to RawPom?

If so we can then still look to make that more explicit in the plugin for instance by suggesting to run that recipe, as opposed to making the changes proposed in #5615 and downstream from there.

timtebeek avatar Jun 13 '25 18:06 timtebeek

Just had a closer look at this; thanks again! So traditionally our approach has been not to put the details in in the exception message (there's limited formatting options there), but instead to make the failure available through a marker on the source file, which can then be exported.

If you run the following command on your project

mvn -U org.openrewrite.maven:rewrite-maven-plugin:run -Drewrite.activeRecipes=org.openrewrite.FindParseFailures -Drewrite.exportDatatables=true

Then you should see a org.openrewrite.table.ParseFailures data table produced in target/ listing the source path, exception type and full stacktrace. As per https://docs.openrewrite.org/recipes/core/findparsefailures and documented on https://docs.openrewrite.org/reference/faq#my-recipe-runs-but-is-not-making-any-changes-whats-happening

It could also be that a particular file is not parsed correctly. In such cases you'll see log line output which files failed to parse. You can use the Find source files with ParseExceptionResult markers diagnostic recipe to find & report these issues. Note that this again produces a data table for you to inspect.

Can you confirm that indeed already gives you the details you'd have needed to troubleshoot without making any changes to RawPom?

If so we can then still look to make that more explicit in the plugin for instance by suggesting to run that recipe, as opposed to making the changes proposed in #5615 and downstream from there.

Hi, I did run the proposed maven command line against the provided reproducer project, and the target folder is not even created, and there is no datatable put out. But again that is to be expected because my understanding is that with this failure we do not even arrive to point where any recipe is run because the POM parsing is failing before that.

edeweerd1A avatar Jun 26 '25 09:06 edeweerd1A