Skip to content

It's unclear how to suppress check of string literal comparison #2

@espertus

Description

@espertus

The following codes is validated correctly:

@SuppressWarnings({"StringEquality"})
@Incorrect
public class Lint{
  public static void main(String[] args){
    String formatString = "--format";
    if (args[0] == formatString) {
      System.out.println("match");
    }
  }
}

This code, which adds a suppression and has a comparison to a string literal, fails:

@SuppressWarnings({"StringEquality", "StringLiteralEqualityCheck"})
@Incorrect
public class Lint{
  public static void main(String[] args) {
    if (args[0] == "--format") {
      System.out.println("match");
    }
  }
}

I understand the error message that was displayed:

java.lang.IllegalStateException: Invalid error: edu.illinois.cs.cs125.questioner.lib.IncorrectFailedLinting: Incorrect code failed linting with checkstyle
Literal Strings should be compared using equals(), not '=='.

I do not understand how to suppress the error. From searching online, it appears I should disable StringLiteralEqualityCheck; however, doing so had no effect.

How do I know which warning to suppress?

This is low priority, because I can easily work around it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions