Warning fixes and extra sanity checks Ref #16376 (cherry picked from commit 77087db79318443fff1b6fe3c91b55a315c5bf92)