Fixed checks on "HasAttribute" that could throw a null exception.