Suggested code changes from Coverity inspection

See https://scan.coverity.com/projects/1983

These should be small uncontroversial changes. Look at the hashCode-related change though, in case it's important to retain the exact partitioning across releases.

(Does this need a JIRA?)