Merge "Refactor the nativePtr validation code to a method."