I have a dummy Java function here. If p is a valid object, t should point to it.
private void turhake(Piece p, Piece t) {
if (null == t && null != p) {
t = p;
if (null == t) System.exit(44);
} else System.exit(43);
}
In the following code I ensure that the above function is only called if p is non null and t is null.
if (threatener != null) System.exit(42);
if (board[row][col] != null) {
turhake(board[row][col], threatener);
if (threatener == null) System.exit(41);
}
The result should be that both p and t (board[row][col] and threatener) point to the same object. However my program exits with the code 41, indicating that t got nullified after the function call. Piece class has a few enum variables, nothing special. If I replace the function call with the following, all is good.
if (threatener != null) System.exit(42);
if (board[row][col] != null) {
threatener = board[row][col];
if (threatener == null) System.exit(41);
}
What makes t point to null after it has successfully been assigned a non null object?