Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java: support LGTM alert suppression using @SuppressWarnings annotations #2152

Merged

Conversation

yh-semmle
Copy link
Contributor

Supports alert suppression of the form @SuppressWarnings("lgtm[query-id]").

@yh-semmle yh-semmle marked this pull request as ready for review October 22, 2019 00:40
@yh-semmle yh-semmle requested a review from a team as a code owner October 22, 2019 00:40
@yh-semmle
Copy link
Contributor Author

Testing using a full LGTM distribution build revealed no performance (or other) issues.

@yh-semmle
Copy link
Contributor Author

@Semmle/doc this affects documentation of alert suppression:

In addition to alert suppression using comments, LGTM now supports alert suppression for Java analysis using @SuppressWarnings annotations. For example, a @SuppressWarnings("lgtm[query-id]") annotation on a method would suppress all alerts for query query-id within that method.

@mchammer01
Copy link
Contributor

mchammer01 commented Oct 22, 2019

@yh-semmle - can you clarify what a method is? An example might help me here (to be included in the help, with an example of annotation for a method, and an existing Java query). Thanks.
That's the topic I'll be updating: https://help.semmle.com/lgtm-enterprise/user/help/alert-suppression.html

@jf205
Copy link
Contributor

jf205 commented Oct 22, 2019

Thanks for the mention @yh-semmle
I'll update the QL command-line tools docs for this change (https://help.semmle.com/wiki/display/SD/Suppressing+alerts)
@mchammer01 will update the LGTM topic

@yh-semmle
Copy link
Contributor Author

can you clarify what a method is? An example might help me here (to be included in the help, with an example of annotation for a method, and an existing Java query).

The existing alert suppression documentation at https://lgtm.com/help/lgtm/alert-suppression#java gives the following example for suppression comments:

void test(int length) {
    int firstIndex = length * 0; // lgtm[java/evaluation-to-constant]
    int secondIndex = length * 1;
    int thirdIndex = length * 2;
    ...
}

The alert can now also be suppressed as follows:

@SuppressWarnings("lgtm[java/evaluation-to-constant]")
void test(int length) {
    int firstIndex = length * 0;
    int secondIndex = length * 1;
    int thirdIndex = length * 2;
    ...
}

Note that this will suppress all alerts for this query in the above method (Java terminology for "function" in other languages), not just on the line where the suppression comment was located.

Note that @SuppressWarnings annotations are a standard feature of the Java language, so should not need any explanation for Java developers (see the Javadoc or this tutorial).

@aschackmull aschackmull merged commit fe2988a into github:master Oct 24, 2019
@mchammer01
Copy link
Contributor

Thanks for the info @yh-semmle 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants