google / google/error-prone

Synthetic accessor method generation check.

Open
#537 4 comments 6 reactions 0 assignees View on GitHub
Type-NewCheck
Dominant language
Java
Stars
7.2k
Forks
820
Avg merge
5h 9m
Merged PRs (30d)
50

Description

Method count is an ever-touchy subject for Android libraries and applications. The synthetic accessor methods produced by javac when accessing a private resource across a nested class boundary is a almost always needless and can be avoided by promoting something to package scoped.

The main cases where this happens:
* Accessing a private method/ctor across a nested class boundary. Fix: Change method/ctor to package scoped.
* Accessing a private field across a nested class boundary. Fix: Change field to package scoped.
* Accessing an _implicit_ private constructor on a private, nested class. Fix: Add an explicit package-scoped empty constructor to the nested class (the type can remain private) or make the type package-scoped.

This check should probably be off by default since it happens A TON when you're not paying attention to it and when targeting the JVM it's usually not a concern. Furthermore, future versions of Java will allegedly offer "nest mates" which altogether remove the need for synthetic accessor method generation so removing it only really makes sense for Android apps and libraries.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.