Fix PMD and Findbugs warnings and a possible NPE