JD.METHOD.CBS
Method can be static
JD.METHOD.CBS is triggered when a virtual method does not access member variables or call other virtual methods.
Vulnerability and risk
The risk is the unjustifiably increased memory footprint of a class. This is particularly sensitive matter for mobile and embedded systems. To avoid this issue, reported methods should become static.
Vulnerable code example 1
Copy
public class A {
public static int val = 0;
public int counter = 0;
public int foo() { // method can be static
val = 109;
return val;
}
public int test() { // method can not be static
val = 100*counter;
return val;
}
}
JD.METHOD.CBS is reported for line 5: Method 'foo' can be declared static.
The method 'foo' uses only static class member ‘val’ and doesn’t call any virtual class methods.
Fixed code example 1
Copy
public class A {
public static int val = 0;
public int counter = 0;
public static int foo() { // method can be static
val = 109;
return val;
}
public int test() { // method can not be static
val = 100*counter;
return val;
}
}