Detection of duplicate conditions in else-if clauses (unreachable code paths)
During code review, the following code snippet has been discovered:
if(trigger instanceof PeriodicTimeTrigger) { return formatTimeTriggeredResourceAllocation(resourceAllocation); } else if(trigger instanceof PeriodicTimeTrigger) { return formatRateConstraintResourceAllocation(resourceAllocation); }
The second part of the else-if block is obviously not reachable. Probably, the condition in the else-if statement is the result of a copy’n paste error.
For these kinds of problems, the existing warning-generator in org.fortiss.ide.dev-tools could be modified to detect these errors by a string compare operation. It would detect at least a portion the copy’n paste errors.
Side note: The “real” solution would be actually a cecker in java that performs the dead-code analysis, since more complicated (and not exactly the same conditions) could also result in dead code paths. However, this checker in the java compiler does not even detect this ovious case…
(from redmine: issue id 2675, created on 2016-08-11, closed on 2018-03-05)