[Objective-C] [S1854] False Positive report of dead store inside GCD block

  • What language is this for?

  • Which rule?
    S1854 - Unused assignments should be removed

  • Are you using
    SonarQube - I think it’s 8.x, trying to get precision on this from our devops.

  • How can we reproduce the problem? Give us a self-contained snippet of code (formatted text, no screenshots)

@property (nonatomic, strong) dispatch_queue_t syncQueue;
@property (nonatomic, strong) NSMutableDictionary<NSNumber *, NSNumber*> *threadSafeDict;

-(void)updateDictValue:(NSUInteger)value forKey:(NSUInteger *)key {
    dispatch_barrier_async(_syncQueue, ^{
        NSNumber *key = [NSNumber numberWithUnsignedInteger:key]; // (1)
        _threadSafeDict[key] = [NSNumber numberWithUnsignedInteger:value];

(1) triggers Value stored to ‘key’ during its initialization is never read

  • Why do you believe it’s a false-positive/false-negative?
    key is used immediately in the next line.

Hey there.

Thanks for the report. We won’t be able to comment on it further until we know exactly what version of SonarQube is being used.

Sorry for the delay, I went OOO and got response just now.
We’re using 8.9.10 (build 61542)

Hey there.

Can you please upgrade to SonarQube v9.9 LTS and see if the false-positive persists? There have been efforts to suppress false-positives on this rule in the v9.x series.