if part is null then this will throw a NullPointerException because the equals method will be called on a null value. Use: part != null