Code smell implementation identical objective C

Greetings Sonar community.

We are running an objective C scan on code and this code below gets flagged with a “code smell” that the addObject is identical to the removeObject.

" Update this method so that its implementation is not identical to addObject."

-(void)addObject:(UIViCo*)vc
{
    if (vc == nil)
        return;
    @synchronized (self) {
        [pointerArray addPointer:(__bridge void* _Nullable)(vc)];
    }
}
-(void)removeObject:(UIViCo*)vc {
Update this method so that its implementation is not identical to addObject.
    if (vc == nil)
        return;
    @synchronized (self) {
        for (NSInteger i = (NSInteger)pointerArray.count - 1; i >= 0; i--) {
            if ([pointerArray pointerAtIndex:(NSUInteger)i] == (__bridge void* _Nullable)(vc)) {
                [pointerArray removePointerAtIndex:(NSUInteger)i];
            }

As you can see the removeObject is significantly different to the addObject. The example from “why is this an issue” shows 2 identical functions and would then I believe require us to change the variable vc to say vb in the second function. IMHO this makes readability worse.

Could someone explain this code smell better?

  • which versions are you using
    9.9.2
  • how is SonarQube deployed: zip, Docker, Helm
    Server install on vm
  • what are you trying to achieve
    Compliant scan
  • what have you tried so far to achieve this
    Normal product configuration.

Hey there (and nice name!)

Your version is past EOL. You should upgrade to either the latest version or the current LTA (long-term active version) at your earliest convenience. Your upgrade path is:

9.9.2 → 2025.1.1

You may find these resources helpful:

If you have questions about upgrading, feel free to open a new thread for that here.

If the issue persists after upgrade, please come back to us.