I recently stumbled upon the following warning using PMD (built-in hudson), my code seems to suffer from CollapsibleIfStatements , which I don't quite understand. The code is as follows:
// list to be filled with unique Somethingness List list = new ArrayList(); // fill list for (SomeObject obj : getSomeObjects()) { // interating if (!obj.getSomething().isEmpty()) { // check if "Something" is empty * if (!list.contains(obj.getSomething())) { // check if "Something" is already in my list ** list.add(obj.getSomething()); // add "Something" to my list } } }
In my opinion, this code is no more โlegibleโ (otherwise it will be even more unreadable for the next guy reading the code). On the other hand, I want to solve this warning (without deactivating PMD;).
source share