dpc-common/src/main/java/gov/cms/dpc/fhir/validations/DPCProfileSupport.java
Method validateCode
has 5 arguments (exceeds 4 allowed). Consider refactoring. Wontfix
Wontfix
public CodeValidationResult validateCode(FhirContext fhirContext, String s, String s1, String s2, String s3) {
Method validateCodeInValueSet
has 5 arguments (exceeds 4 allowed). Consider refactoring. Wontfix
Wontfix
public CodeValidationResult validateCodeInValueSet(FhirContext theContext, String theCodeSystem, String theCode, String theDisplay, @Nonnull IBaseResource theValueSet) {
Return an empty collection instead of null. Open
Open
return null;
- Read upRead up
- Exclude checks
Returning null
instead of an actual array or collection forces callers of the method to explicitly test for nullity, making them more
complex and less readable.
Moreover, in many cases, null
is used as a synonym for empty.
Noncompliant Code Example
public static List<Result> getResults() { return null; // Noncompliant } public static Result[] getResults() { return null; // Noncompliant } public static void main(String[] args) { Result[] results = getResults(); if (results != null) { // Nullity test required to prevent NPE for (Result result: results) { /* ... */ } } }
Compliant Solution
public static List<Result> getResults() { return Collections.emptyList(); // Compliant } public static Result[] getResults() { return new Result[0]; } public static void main(String[] args) { for (Result result: getResults()) { /* ... */ } }
See
- CERT, MSC19-C. - For functions that return an array, prefer returning an empty array over a null value
- CERT, MET55-J. - Return an empty array or collection instead of a null value for methods that return an array or collection