openrewrite / rewrite

Automated mass refactoring of source code.
https://docs.openrewrite.org
Apache License 2.0
2.03k stars 300 forks source link

Failed to parse pom: Cannot construct instance of "org.openrewrite.maven.tree.ProfileActivation" #1427

Closed josemariavillar closed 2 years ago

josemariavillar commented 2 years ago

Good afternoon,

With version 7.19.0 a failure is occurring when you try to parse the project POM.

[INFO] --- rewrite-maven-plugin:4.20.0:dryRun (default-cli) @ test-project ---
[INFO] Using active recipe(s) [com.yourorg.UpgradePom]
[INFO] Using active styles(s) []
[INFO] Validating active recipes...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  30.399 s
[INFO] Finished at: 2022-03-02T15:26:23+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.openrewrite.maven:rewrite-maven-plugin:4.20.0:dryRun (default-cli) on project test-project: Execution default-cli of goal org.openrewrite.maven:rewrite-maven-plugin:4.20.0:dryRun failed: Failed to
parse pom: Cannot construct instance of `org.openrewrite.maven.tree.ProfileActivation` (although at least one Creator exists): no default no-arguments constructor found
[ERROR]  at [Source: (FileInputStream); line: 4972, column: 10] (through reference chain: org.openrewrite.maven.internal.RawPom["profiles"]->org.openrewrite.maven.internal.RawPom$Profiles["profile"]->java.util.ArrayList[6]->org.open
rewrite.maven.internal.RawPom$Profile["activation"])

Debugging, I have seen that the problem occurs when using the RedHat infinispan library. When trying to parse the parent POM of the infinispan dependency the exception occurs. Attached is the POM that is failing:

https://maven.repository.redhat.com/ga/org/infinispan/infinispan-parent/9.4.21.Final-redhat-00002/infinispan-parent-9.4.21.Final-redhat-00002.pom

The exception occurs in the "parse" method of the RawPom class.

https://github.com/openrewrite/rewrite/blob/c6cc7bd0aa18af515ce2e9658f7e3e1daba9b956/rewrite-maven/src/main/java/org/openrewrite/maven/internal/RawPom.java#L101-L109

With version 7.17.3 it works without problems.

I attach a test project where this failure is reproduced: https://github.com/josemariavillar/test_project/tree/failed_parse_pom

traceyyoshima commented 2 years ago

Thanks again @josemariavillar for the report, we'll take a look!

tkvangorder commented 2 years ago

Not fixed yet, but we have a lead now.

This failure occurs when there is an empty <activation/> tag in the pom

tkvangorder commented 2 years ago

@josemariavillar We finally tracked this down and have fixed it! Thanks for reporting!

josemariavillar commented 2 years ago

Great, @tkvangorder thank you very much for your great work. I validate it and let you know

josemariavillar commented 2 years ago

@tkvangorder unfortunately the problem is not fixed, I have validated the solution with version 4.21.0-SNAPSHOT of the rewrite-maven-plugin and it still gives the same error :(

I have opened a new issue (https://github.com/openrewrite/rewrite/issues/1487) so you can check it.

Thank you very much for your help.