1 package com.puppycrawl.tools.checkstyle.checks.descendanttoken; 2 3 public class InputDescendantTokenStringLiteralEquality 4 { 5 void foo(String name) 6 { 7 if (name == "Lars") 8 { 9 // flagged, should use equals 10 } 11 12 if ("Oleg" == name) 13 { 14 // flagged, should use equals 15 } 16 17 if ("Oliver" == "Oliver") 18 { 19 // doesn't make much sense because this can be evaluated 20 // to true at compile time, but is flagged anyway 21 } 22 23 String compare = "Rick"; 24 if (name == compare) 25 { 26 // currently not flagged. 27 // 28 // Implementing this is very complicated, we would need 29 // - type info on the == operands 30 // - prevent false alarms where the user explicitly wants 31 // to compare object identities 32 // 33 // My current feeling is that we should leave finding 34 // this one to manual code inspections. After all MCI is 35 // what some of us get paid for :-) 36 } 37 38 if ("Rick".toUpperCase(java.util.Locale.getDefault()) 39 == "Rick".toLowerCase(java.util.Locale.getDefault())) 40 { 41 // completely dynamic, don't flag 42 } 43 } 44 }