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

Incorrect handling of [string literal].equals() #471

Closed
blindpirate opened this issue Mar 14, 2019 · 1 comment · Fixed by #472
Closed

Incorrect handling of [string literal].equals() #471

blindpirate opened this issue Mar 14, 2019 · 1 comment · Fixed by #472

Comments

@blindpirate
Copy link
Contributor

Context

The following code can't pass EqualsAvoidNullRule:

	public class Test {
		private static final String VERSION = System.getProperty("v");
		public boolean isJava6(){
			return "1.6".equals(VERSION);
		}
	}
【"1.6""1.6"】应该作为equals的参数,而不是调用方

Another sample:

	public class Test {
		public boolean isJava6(){
			return "1.6".equals("1.6");
		}
	}
blindpirate added a commit to blindpirate/p3c that referenced this issue Mar 14, 2019
This fixes alibaba#471

Previously, the following code can't pass EqualsAvoidNullRule:

public class Test {
  private static final String VERSION = System.getProperty("v");
  public boolean isJava6(){
    return "1.6".equals(VERSION);
  }
}

This PR fixes this issue by checking if the caller is a literal.
@xuantan
Copy link
Collaborator

xuantan commented Mar 19, 2019

好的,多谢反馈

fw8899 pushed a commit that referenced this issue Mar 29, 2019
This fixes #471

Previously, the following code can't pass EqualsAvoidNullRule:

public class Test {
  private static final String VERSION = System.getProperty("v");
  public boolean isJava6(){
    return "1.6".equals(VERSION);
  }
}

This PR fixes this issue by checking if the caller is a literal.
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 a pull request may close this issue.

2 participants