01: package com.puppycrawl.tools.checkstyle.coding;
02:
03: /**
04: * Input file for the StringLiteralEqualityCheck
05: * @author Lars Kühne
06: */
07: public class InputStringLiteralEquality {
08: void foo(String name) {
09: if (name == "Lars") {
10: // flagged, should use equals
11: }
12:
13: if ("Oleg" == name) {
14: // flagged, should use equals
15: }
16:
17: if ("Oliver" == "Oliver") {
18: // doesn't make much sense because this can be evaluated
19: // to true at compile time, but is flagged anyway
20: }
21:
22: String compare = "Rick";
23: if (name == compare) {
24: // currently not flagged.
25: //
26: // Implementing this is very complicated, we would need
27: // - type info on the == operands
28: // - prevent false alarms where the user explicitly wants
29: // to compare object identities
30: //
31: // My current feeling is that we should leave finding
32: // this one to manual code inspections. After all MCI is
33: // what some of us get paid for :-)
34: }
35:
36: if ("Rick".toUpperCase() == "Rick".toLowerCase()) {
37: // completly dynamic, don't flag
38: }
39: }
40: }
|