diff options
author | rnveach <rveach02@gmail.com> | 2015-10-16 23:02:06 -0400 |
---|---|---|
committer | Roman Ivanov <ivanov-jr@mail.ru> | 2015-10-17 05:19:17 -0700 |
commit | de60ea7b86b5ea25338dfe8a300db9d179004812 (patch) | |
tree | 67e8e93a180a21c92a2a1cea948787cbe613c13d /src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputStringLiteralEquality.java | |
parent | 5f3eced2d85c10407b5ba1f38c06af05715d9bd7 (diff) | |
download | checkstyle-de60ea7b86b5ea25338dfe8a300db9d179004812.tar.gz |
Issue #2161: unify test input locations for coding package
Diffstat (limited to 'src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputStringLiteralEquality.java')
-rw-r--r-- | src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputStringLiteralEquality.java | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputStringLiteralEquality.java b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputStringLiteralEquality.java new file mode 100644 index 000000000..d6609d39a --- /dev/null +++ b/src/test/resources/com/puppycrawl/tools/checkstyle/checks/InputStringLiteralEquality.java @@ -0,0 +1,43 @@ +package com.puppycrawl.tools.checkstyle.checks; + +public class InputStringLiteralEquality +{ + void foo(String name) + { + if (name == "Lars") + { + // flagged, should use equals + } + + if ("Oleg" == name) + { + // flagged, should use equals + } + + if ("Oliver" == "Oliver") + { + // doesn't make much sense because this can be evaluated + // to true at compile time, but is flagged anyway + } + + String compare = "Rick"; + if (name == compare) + { + // currently not flagged. + // + // Implementing this is very complicated, we would need + // - type info on the == operands + // - prevent false alarms where the user explicitly wants + // to compare object identities + // + // My current feeling is that we should leave finding + // this one to manual code inspections. After all MCI is + // what some of us get paid for :-) + } + + if ("Rick".toUpperCase() == "Rick".toLowerCase()) + { + // completly dynamic, don't flag + } + } +} |