You will get  NPE here when calling trim() if there is no duplicate, so add a check for null please