groovy / groovy/groovy-eclipse

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

Open
#1,333 0 comments 0 reactions 1 assignee View on GitHub

@eric-milles is already working on this.

Since Jan 10, 2022.

enhancement
Dominant language
Java
Stars
681
Forks
197
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.