Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes uber#374 Avoid throwing exceptions when the source code contains records. Since records are a new kind of class, refactor the switch statements that make assertions about which elements and trees represent classes. Use general purpose `isClassElement` and `isClassTree` methods that are forward-compatible with records instead of enumerating `ElementKind` or `Tree.Kind` constants. Refactor `checkFieldInitialization` to ignore final fields. This check was wrongly flagging records because it couldn't analyze record constructors properly. Without the change to ignore final fields, this check runs into two kinds of trouble with records: 1. It doesn't inspect record constructors at all because they are generated. `NullAway.isConstructor(MethodTree)` returns false and so those trees are skipped. 2. The trees for the generated constructors don't contain explicit field assignments. That's just not how those were implemented. Something else is reponsible for assigning the fields at runtime, apparently. Rather than trying to teach NullAway about record constructors specifically, count on javac to verify that all final fields are initialized. Presumably, if NullAway were to complain that a constructor did not initialize a final field, that complaint would be redundant (with the error that javac would produce) at best and incorrect otherwise.
- Loading branch information