Priority
Normal
Type
Bug 
State
Fixed 
Assignee
Bas Leijdekkers 
Subsystem
Editor. Intention Actions 
Affected versions
Fixed in
Fixed in build
Next build 
Build
7590
Fixed in build
8088
Severity
0
  • Submitted by   Serge Baranov
    2 years ago (06 Jan 2008 22:56)
  • Updated by   root
    3 weeks ago (17 Jan 2010 19:57)
  • Jira: IDEA-42513
    (history, comments)

IDEA-42513

Bug in ternary to if-else auto refactoring

1
Support feedback:

There is a bug in the automatic refactoring from the ternary operator to if-else. I am using IntelliJ version 7.02. I have provided the following
class to illustrate the problem.

public class ReplaceTernaryWithIfBugReport {
        private Object value;

        public boolean equals(Object o) {
                if (this == o) {
                        return true;
                }
                if (o == null || getClass() != o.getClass()) {
                        return false;
                }

                ReplaceTernaryWithIfBugReport that = (ReplaceTernaryWithIfBugReport)o;

                if (value != null ? !value.equals(that.value) : that.value != null) {
                        return false;
                }

                return true;
        }
        
        public boolean equalsAfterAutomaticRefactoring(Object o) {
                if (this == o) {
                        return true;
                }
                if (o == null || getClass() != o.getClass()) {
                        return false;
                }

                ReplaceTernaryWithIfBugReport that = (ReplaceTernaryWithIfBugReport)o;

                // I used the "Replace ?: with if-else light-bulb refactoring on 
                // if (value != null ? !value.equals(that.value) : that.value != null) {
                // which resulted in the following:
                if (value != null) {
                        if (!value.equals(that.value)) {
                                return false;
                        } else if (that.value != null) {
                                return false;
                        }
                }

                return true;
        }
        public int hashCode() {
                return (value != null ? value.hashCode() : 0);
        }
}


Issue was resolved
Comments (0)
 
History (1)
 
Links
 
Issue has no comments