use target_ref.get() == null and also switch the target_ref == nul and put it on left side. Else it will never check it since it will NPE first.