spdx / Spdx-Java-Library

Java library which implements the Java object model for SPDX and provides useful helper functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

dwalluck opened this issue · 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.

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.