There appears to be a bug in the Java entry for this task - and hence probably in all the other entries which are direct translations of this entry. This bug occasionally manifests itself by throwing an ArrayIndexOutOfBoundsException in the printResult() method and, as far as I can tell, is always caused by some value in the last row of the grid array being equal to -1.
For now I have applied a temporary fix to my Kotlin entry whereby out of range values are replaced by a blank (i.e. a dash). However, the author of the Java entry may like to see if there is a way to prevent out of bounds values from occurring in the first place so we can use that instead.--PureFox (talk) 17:50, 29 September 2017 (UTC)