Skip to content

Add warning for property assignment using private setter in non-final class #1333

Open
@eric-milles

Description

@eric-milles

Consider the following:

class C {
  def m() { x = null }
  private void setX(x) {}
}
class D extends C /*implements Map*/ {
  /*
  @Delegate Map m
  void setX(x) { }
  void set(String name, value) { }
  */
}
new D().m()

The expression "x = null" will not make use of the private setter of C if one of the items in D is uncommented. "setX(null)" is safe or changing the visibility of setX to at least package-private or enabling static compilation for the call site prevents the interception as well. A warning could help bring awareness to this possibility.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions