Implicit Public Visibility of Apex Classes and Methods Without Explicit Access Modifiers
0 reputation · 10 Feb 2023, 16:30 UTC
In Apex, any top‑level class declared without an explicit access modifier is implicitly public, and methods inside such a class also default to public. This default visibility can unintentionally expose internal implementation details to other code, creating security and maintenance risks.
Developers must verify that the intended access level matches the design, yet the language provides no compile‑time warning for accidental public exposure. The challenge is to establish a reliable method for auditing and enforcing visibility declarations across projects.
What is the recommended approach to enforce private visibility for internal utility classes in Apex?
Can a static analysis rule be defined to flag missing access modifiers on all top‑level classes and methods?
Is there a configuration or tool that treats default visibility as a compilation error?