Вебинар: Стратегия без иллюзий: как превращать цели в результаты - 19.08
V6052. Calling an overridden method in parent-class constructor may lead to use of uninitialized data.
V6052 Calling overridden 'toString' method in 'BeanInfo' parent-class constructor may lead to use of uninitialized data. Inspect field: bindings. InterceptorInfo.java(265)
public class InterceptorInfo extends BeanInfo
implements Comparable<InterceptorInfo> {
private final Set<AnnotationInstance> bindings;
....
InterceptorInfo(. . . ., Set<AnnotationInstance> bindings) {
super(. . . .);
this.bindings = bindings;
....
}
@Override
public String toString() {
return "INTERCEPTOR bean [bindings=" + bindings +
", target=" + getTarget() + "]";
}
}
public class BeanInfo implements InjectionTargetInfo {
BeanInfo(....) {
....
this.identifier = Hashes.sha1_base64(
(identifier != null ? identifier : "") +
toString() + beanDeployment.toString()
);
....
}
}
When `InterceptorInfo` is initialized, the constructor of its parent class, `BeanInfo`, is called first. That constructor, in turn, calls the `toString` method, which is overridden in the `InterceptorInfo` class. At this point, the `toString` method uses the `bindings` field before it's been initialized.
V6052 Calling overridden 'isBinaryContents' method in 'TextWithOpen' parent-class constructor may lead to use of uninitialized data. Inspect field: binary. TextWithOpenFile.java(77), TextWithOpen.java(59)
public class TextWithOpen extends Composite {
public TextWithOpen(
Composite parent,
boolean multiFS,
boolean secured
) {
super(parent, SWT.NONE);
....
if (!useTextEditor && !isBinaryContents()) { // <=
....
editItem.setEnabled(false);
}
....
}
protected boolean isBinaryContents() {
return false;
}
}
public class TextWithOpenFile extends TextWithOpen {
private final boolean binary;
....
public TextWithOpenFile(
Composite parent,
String title,
String[] filterExt,
int style,
boolean binary,
boolean multiFS,
boolean secured
) {
super(parent, multiFS, secured); // <=
this.title = title;
this.filterExt = filterExt;
this.style = style;
this.binary = binary; // <=
}
@Override
protected boolean isBinaryContents() {
return binary;
}
....
}
isBinaryContents() called in the parent constructor before this.binary initialized in the TextWithOpenFile constructor. Therefore, isBinaryContents always returns false, because this is the default value of boolean.