ISPN-5096 Avoid NPE beans when scanning for duplicates

https://issues.jboss.org/browse/ISPN-5096
Do you know what can cause the bean to be `null`? It would be nice to have a comment here explaining the null check.
Also, I'd rather add a single `if (bean != null)` check around lines 343-347.