semver4j icon indicating copy to clipboard operation
semver4j copied to clipboard

NPE when using Requirement.buildNPM with ^16.0.0-0

Open mealingr opened this issue 2 years ago • 2 comments

Trying to create an npm version requirement of ^16.0.0-0 results in a NullPointerException i.e.

Requirement.buildNPM("^16.0.0-0");

gives

java.lang.NullPointerException: null
	at com.vdurmont.semver4j.Semver.<init>(Semver.java:26)
	at com.vdurmont.semver4j.Requirement.hyphenRequirement(Requirement.java:487)
	at com.vdurmont.semver4j.Requirement.evaluateReversePolishNotation(Requirement.java:338)
	at com.vdurmont.semver4j.Requirement.buildWithTokenizer(Requirement.java:138)
	at com.vdurmont.semver4j.Requirement.buildNPM(Requirement.java:112)

Whereas this requirement is parseable by node-semver (which is what npm uses) https://github.com/npm/node-semver i.e.

npm install -g semver
...
// In Node.js console
const semver = require('semver')
undefined
semver.satisfies('16.14.0', '^16.0.0-0')
true

This requirement can arise from e.g. trying to install enzyme-adapter-react-16 using npm 6.14.13 npm install [email protected]

Then in the package-lock.json you'll see

"enzyme-adapter-react-16": {
      "version": "1.15.6",
      ...
      "requires": {
        ...
        "react-test-renderer": "^16.0.0-0",
      }
    }

mealingr avatar Nov 03 '21 15:11 mealingr

@mealingr if you are still interesting, I've made copy of this lib and fix bug reported by you. Look for version 2.0.1

piotrooo avatar Jul 22 '22 22:07 piotrooo

@mealingr if you are still interesting, I've made copy of this lib and fix bug reported by you. Look for version 2.0.1

Thank you @piotrooo for taking the time to fix this, happy to take a look

mealingr avatar Sep 20 '22 11:09 mealingr