5

if we have code:

@Contract("null, _, _ -> fail")
static void ifNull(Object object, ErrorType errorType, Object... args) throws ServiceException {
    if (object == null) {
        ExceptionFactory.throwServiceException(errorType, args);
    }
}

and

private boolean checkSeqValue(Sequence sequence, @Nonnull Number value) {
...
}

and somewhere:

ifNull(value, ErrorType.NOT_FOUND, "Value for a sequence", "name = " + seqName);
if (checkSeqValue(sequence, value)) {
        result = value;
}

then SonarLint plugin shows a Critical bug:

squid:S2637 "@NonNull" values should not be set to null

for checkSeqValue Parameter 2 to this call is marked javax.annotation.Nonnull but null passed

directly check:

    if (value == null) {
        throw new ServiceException();
    }            
    if (!isNeedCheck || checkSeqValue(sequence, value)) {
        result = value;
    }

doesn't give any sonar errors.

is anybody know how make sonar take into consideration @Contract annotation?

SonarLint plugin version 3.3.0.2482

SonarQube 6.0

Intellij idea 2018.1.1

Thanks a lot

magway
  • 51
  • 3
  • 2
    I can confirm this for sonarqube 7.1 too. – Hannes Apr 23 '18 at 13:42
  • Even if in this thread it was said that the feature was on the roadmap, it seems that with Sonarqube 9.3 it is still not implemented https://community.sonarsource.com/t/support-for-contract-annotations/43143 – dcolazin Apr 26 '23 at 13:22

0 Answers0