Pattern: this
reference escapes constructor
Issue: -
Reports constructors passing the this
reference to other methods. This equals exposing a half-baked objects and can lead to race conditions during initialization.
Example of violations:
class EventListener {
EventListener(EventPublisher publisher) {
publisher.register(this)
new WorkThread(publisher, this).start()
new AnotherWorkThread(listener: this)
}
}