Skip to content

[win32] Widget constructor calls overrideable public method; breaks EGit's FindToolbar #2733

@tomaswolf

Description

@tomaswolf

Describe the bug
The Widget constructor

public Widget (Widget parent, int style) {
checkSubclass ();
checkParent (parent);
this.style = style;
this.nativeZoom = parent != null ? parent.nativeZoom : DPIUtil.getNativeDeviceZoom();
display = parent.display;
reskinWidget ();
notifyCreationTracker();
registerDPIChangeListener();
}
void registerDPIChangeListener() {
if (display.isRescalingAtRuntime()) {
this.addListener(SWT.ZoomChanged, event -> {
float scalingFactor = 1f * DPIUtil.getZoomForAutoscaleProperty(event.detail) / DPIUtil.getZoomForAutoscaleProperty(nativeZoom);
handleDPIChange(event, scalingFactor);
});
}
}

calls via registerDPIChangeListener the public and overrideable method addListener. If that method is overridden in a subclass it will run before the subclass instance is initialized. This is bad practice, and in fact it breaks EGit's FindToolbar: see eclipse-egit/egit#117 .

Possible fix

Replace the call to this.addListener at

by this._addListener (with underscore, package-private).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions