in a simplified version, what i have is this:
public class MyLabel extends JLabel implements MouseListener{
private SomeControl control;
public MyLabel(SomeControl control){
this.addMouseListener(this);
this.control = control;
}
@Override
public void mouseClicked(MouseEvent arg0) {
Object x = this.control.getSomeProperty();
}
Even though i debug and verify when constructing the MyLabel instance that the control and its someProperty is not null, when the event is fired and handler steps in, it shows the someProperty as if it was null, what could be the problem here?
In the
MyLabelconstructor, the value ofcontrolis null (by default) whenthisis added as theMouseListener. If the listener were invoked at this point, it would see the null value. Subsequently, thecontrolvalue is updated with the non-null parameter value, as the debugger reports. I suspect the anomaly may be an escapedthis, as discussed here.