History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: IDEADEV-16684
Type: Bug Bug
Status: Open Open
Priority: Normal Normal
Assignee: Maxim Shafirov
Reporter: Serge Baranov
Votes: 1
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
IDEA: Development

'condition is always false' warning is incorrect

Created: 27 Apr 07 10:27   Updated: 03 May 07 16:19
Component/s: Code Analysis. Inspection
Fix Version/s: None

Original Estimate: Unknown Remaining Estimate: Unknown Time Spent: Unknown

Build: 6,180
Severity: Medium


 Description  « Hide
Usually the boolean warnings are rather clever, but I have a case where I'm warned that the condition is always false, when in fact
it's not. Here's the code (feel free to republish):
public static String camelToUpper(String camel) {
    camel = camel.replaceAll("\\+", "_PLUS");
    camel = camel.replaceAll("\\-", "_MINUS");
    camel = camel.replaceAll("&", "AND");
    camel = camel.replaceAll("[/@()]", "_");
    camel = camel.replaceAll("\\s", "_");
    camel = camel.replaceAll("'", "");
    boolean wasLower = false;
    String out = "";
    String upper = camel.toUpperCase();
    for (int i = 0; i < camel.length(); i++) {
      char c = upper.charAt(i);
      boolean isUpper = (c == camel.charAt(i));
      if (isUpper && wasLower && c != '_')
        out = out + "_";
      out = out + c;
      wasLower = !isUpper;
    }
    if (out.substring(0, 1).matches("[0-9]"))
      out = "_" + out;
    out = out.replaceAll("_+", "_");
    out = out.replaceAll("_$", "");
    return out;
  }

Intellij warns that the condition '(isUpper && wasLower && c != '_')' as always false. This in fact is incorrect, and it's quite
easy to show that the statement inside the condition does get executed.



 All   Comments   Work Log   Change History      Sort Order:
There are no comments yet on this issue.