allwpilib
allwpilib copied to clipboard
[epilogue] Use reflection to access non-public superclass fields
A sort of patch/continuation to #7993. @SamCarlberg and I overlooked that VarHandler does not allow you to violate some Java access permissions, such as accessing a private variable of a superclass or accessing a protected or package-private variable of a superclass if you're not in that package. As a result, some of the superclass-logging features of #7993 didn't work as intended:
- A
java.lang.IllegalAccessExceptionwould be raised on startup if a logged class' superclass had a@Loggedprivatefield - A
java.lang.IllegalAccessExceptionwould be raised on startup if a logged class' superclass had a@Loggedprotectedor package-private field and the child class wasn't in the same package
This PR fixes this by switching to using reflection to handle non-public superclass fields. This lets me revert the change from 7993 that made all non-public fields get accessed with VarHandler's - this can go back to being used for private-non-superclass fields only like it was before, which simplifies a lot of loggers and cleans up a lot of the unit test outputs :)
I pulled this set of changes into the robot project that helped me catch the issues and all seems to be working well - cross-package superclass fields are logging as intended.