Spdx-Java-Library icon indicating copy to clipboard operation
Spdx-Java-Library copied to clipboard

Method `LicenseInfoFactory::getListedLicenseById` never returns `null`

Open dwalluck opened this issue 9 months ago • 1 comments

The javadoc for LicenseInfoFactory::getListedLicenseById states that it returns the "SPDX listed license or null if the ID is not in the SPDX license list". But, it looks like that for any value I pass in, it seems to return a SpdxListedLicense with the id set to that value (licenseId).

Therefore, instead of simply calling this method, I must check whether licenseId is contained in LicenseInfoFactory::getSpdxListedLicenseIds before calling the method.

dwalluck avatar May 02 '24 14:05 dwalluck

Thanks @dwalluck for pointing this out. I looked at the code, and it looks like it will create the license if it doesn't exist based on this method which defaults to creating the class.

There are a couple possible solutions - check before return or catch the error with create=false (a higher performance solution).

I can take a look at a solution after implementing the SPDX 3.0 support - or if you'd like to create a PR, I can review / merge.

goneall avatar May 03 '24 01:05 goneall