squid:CallToDeprecatedMethod should not be a problem in code deprecated itself

512 views
Skip to first unread message

Vincent Privat

unread,
Jul 27, 2017, 3:03:19 PM7/27/17
to SonarQube
Hello,

Considering this deprecated interface:

/**
* @deprecated use ModifierExListener instead
*/
@Deprecated
@FunctionalInterface
public interface ModifierListener {
   void modifiersChanged(int modifiers);
}

I believe this usage should not trigger an issue:

    /** @deprecated replaced by {@link #modifierExListeners} */
    @Deprecated
    private final List<ModifierListener> modifierListeners = new CopyOnWriteArrayList<>();

Because the field is itself deprecated. This is how Eclipse allows us to silence deprecated warnings when the situation is under control :)

Also it seems that @SuppressWarnings("deprecation"is not taken into account (at least at method level)?

    @Override
    @SuppressWarnings("deprecation")
    public void eventDispatched(AWTEvent e) {
        KeyEvent ke = (KeyEvent) e;
        // check if ctrl, alt, shift modifiers are changed
        int modif = ke.getModifiers();
        if (previousModifiers != modif) {
            for (ModifierListener m: modifierListeners) { // << SQ issue
                m.modifiersChanged(modif);
            }
        }

Tested with SQ 6.4 / SonarJava 4.11.0.10660.

Vincent

Michael Gumowski

unread,
Jul 31, 2017, 6:21:25 AM7/31/17
to Vincent Privat, SonarQube
Hey Vincent,

Thanks for the feedback. The issue is indeed redundant and, from my point of view, should not be reported. I created the following ticket to handle the issue: SONARJAVA-2411

Regarding usage of SuppressWarning("deprecation"), the only way to remove the SonarJava issues would be to explicitly use the rule key. In your case, by using @SuppressWarnings("squid:CallToDeprecatedMethod") instead.

It made me think that we could, maybe in the future, improve the way we filter issues by mapping rules on compiler warnings, but this is definitely food for thought. I nevertheless created the following ticket to start discuss about it: SONARJAVA-2410
I however cannot guarantee we will implemented any time soon.

Cheers,
Michael


--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/c222c0ee-d1a0-458a-91a4-6fd659cdab9e%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--
Michael Gumowski | SonarSource
Software Developer, Language Team
http://sonarsource.com
Reply all
Reply to author
Forward
0 new messages