liquidz / antq

Point out your outdated dependencies.
Other
403 stars 25 forks source link

Execution error (NullPointerException) at antq.upgrade.pom/version-property-name #217

Closed luigigubello closed 1 year ago

luigigubello commented 1 year ago

Problem:

Under certain conditions, antq crashes when it tries to update dependencies in pom.xml.

Error:

Execution error (NullPointerException) at antq.upgrade.pom/version-property-name (pom.clj:40).
Cannot invoke "clojure.lang.IFn.invoke(Object)" because "loc" is null

How to reproduce:

This bug is interesting because it happens for pom.xml but not for deps.edn.

  1. Create a proof-of-concept deps.edn, it needs to have this condition:
com.foo/foo {:mvn/version "1.0.0"
  :exclusions [com.bar/bar]}
com.bar/bar {:mvn/version "1.0.0"}

We are excluding com.bar/bar from com.foo/foo, but we are adding com.bar/bar in our dependency on the same level of com.foo/foo.

  1. Run the command
clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}}' -M -m antq.core --upgrade --force --directory="/path/to/our/deps.edn"

antq works like a charm.

  1. Now, convert our deps.edn into an equivalent pom.xml by running the command clojure -X:deps mvn-pom. In the pom.xml file we should have:
    <dependency>
      <groupId>com.foo</groupId>
      <artifactId>foo</artifactId>
      <version>1.0.0</version>
      <exclusions>
        <exclusion>
          <groupId>com.bar</groupId>
          <artifactId>bar</artifactId>
        </exclusion>
      </exclusions>
    </dependency>
    <dependency>
      <groupId>com.bar</groupId>
      <artifactId>bar</artifactId>
      <version>1.0.0</version>
    </dependency>
  1. Run the previous command to update pom.xml using antq
clojure -Sdeps '{:deps {com.github.liquidz/antq {:mvn/version "RELEASE"}}}' -M -m antq.core --upgrade --force --directory="/path/to/our/pom.xml"

antq crashes, and it return the initial error:

Execution error (NullPointerException) at antq.upgrade.pom/version-property-name (pom.clj:40).
Cannot invoke "clojure.lang.IFn.invoke(Object)" because "loc" is null

Removing the exclusion from pom.xml, it doesn't crash.

      <exclusions>
        <exclusion>
          <groupId>com.bar</groupId>
          <artifactId>bar</artifactId>
        </exclusion>
      </exclusions>

Is this a bug? Might it be possible to align antq behavior for deps.edn and generated pom.xml? Thanks in advace

liquidz commented 1 year ago

@luigigubello Thanks for your reporting! I could reproduce the problem. It's a bug.

I'll fix it later :)

liquidz commented 1 year ago

@luigigubello I fix the bug in bugfix/pom-exclusions branch. Could you try?

luigigubello commented 1 year ago

@liquidz running antq@da6f5af9a3cd474a3703d0fdcaac5d5dc179550b, the bug seems to be fixed, thank you 🤗

liquidz commented 1 year ago

@luigigubello Thanks for your confirmation! Just released v2.4.1070 :)