de.bund.bfr.knime.pmm.common/src/de/bund/bfr/knime/pmm/common/PmmXmlDoc.java
Method parseElement
has 70 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
private void parseElement(Element rootElement) {
for (Element el : rootElement.getChildren()) {
/*
* if (el instanceof PmmXmlElementConvertable) { elementSet.add(new
* ParametricModel(el)); }
- Create a ticketCreate a ticket
Add a default case to this switch. Open
Open
switch (el.getName()) {
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
The requirement for a final default
clause is defensive programming. The clause should either take appropriate action, or contain a
suitable comment as to why no action is taken.
Noncompliant Code Example
switch (param) { //missing default clause case 0: doSomething(); break; case 1: doSomethingElse(); break; } switch (param) { default: // default clause should be the last one error(); break; case 0: doSomething(); break; case 1: doSomethingElse(); break; }
Compliant Solution
switch (param) { case 0: doSomething(); break; case 1: doSomethingElse(); break; default: error(); break; }
Exceptions
If the switch
parameter is an Enum
and if all the constants of this enum are used in the case
statements,
then no default
clause is expected.
Example:
public enum Day { SUNDAY, MONDAY } ... switch(day) { case SUNDAY: doSomething(); break; case MONDAY: doSomethingElse(); break; }
See
- MITRE, CWE-478 - Missing Default Case in Switch Statement
- CERT, MSC01-C. - Strive for logical completeness