Skip to content

Latest commit

 

History

History
25 lines (18 loc) · 911 Bytes

ThisReferenceEscapesConstructor.md

File metadata and controls

25 lines (18 loc) · 911 Bytes

Pattern: this reference escapes constructor

Issue: -

Description

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)
    }    
}

Further Reading