Fix several dozens of errors/warnings reported by FindBugs

(cherry picked from commit 861b722d3f6b0f186b1f4b5c097bb896f2de74c8)