Well, first off, I'm not sure why masterNumber would be null. I don't think ints can even be null...

Second, masterNumber is being changed in your for statement, by the line:

masterNumber =...