ER-003 do, while, if, and for statements need a brace enclosed block

Severity3
Enabledyes
Waivable
Violation
if (strToProc == null) {
	int c = 0;
	for (int i = 0; i < LOOP_CONST; i++)
		c += i;
	intVal = new Integer(c);
}
else if (strToProc.length() == 0)
	intVal = new Integer(0);
else {
	int a = 0;
	int c = 0;
	while (a < strToProc.length())
		if (strToProc.charAt(a)==CHAR_A) {
			c++;
		}
	a++;
	intVal = new Integer(c);
}
Fix
if (strToProc == null) {
	int c = 0;
	for (int i = 0; i < LOOP_CONST; i++) {
		c += i;
	}
	intVal = new Integer(c);
}
else if (strToProc.length() == 0) {
	intVal = new Integer(0);
}
else {
	int a = 0;
	int c = 0;
	while (a < strToProc.length()) {
		if (strToProc.charAt(a)==CHAR_A) {
			c++;
		}
		a++;
	}
	intVal = new Integer(c);
}


Hammurapi 3 Copyright © 2004 Hammurapi Group. All Rights Reserved.