JAVA.UNINIT.LOCAL_VAR
Uninitialized local variable.
Vulnerability and risk
Using an appropriate value as an initial value when adding or modifying functions may cause unintended operation or inconsistency.
Mitigation and prevention
Local variables should be purposely initialized at declaration time to clarify their use and possible values.
Example 1
Copy
public class C09 {
int m_i; //OK
void test(boolean someCond) {
//detect uninitialized local variable for byte, short, int, long, float, double, boolean, char
byte byteUninitialized; //NG
byteUninitialized = 1;
byte byteInitialized = 1;//OK
short sUninitalzied; //NG
sUninitalzied = 1;
int iUninitalzied; //NG
iUninitalzied = 1;
long lUninitalzied; //NG
lUninitalzied = 1;
float fUninitalzied; //NG
fUninitalzied = 0.1F;
double dbUninitalzied; //NG
dbUninitalzied = 0.1;
boolean isUninitialized;//NG
isUninitialized = false;
char cUninitalzied; //NG
cUninitalzied = 'a';
String sUninialized;//OK
}
}