null != null - any ideas on how to re-arrange the code or prevent this?

Posted by Alex on Stack Overflow See other posts from Stack Overflow or by Alex
Published on 2011-01-14T06:43:55Z Indexed on 2011/01/14 6:53 UTC
Read the original article Hit count: 388

Currently debugging, and found an if-statement which for no (I thought...) reason gave me an NPE, obviously for a reason. Which seemed to be that the statement turned out to be if(false && (null != null || null != Color)).

if(destination != null && (destination.getPiece() != null || destination.getPiece().getColour() != pieceColour)) - the if-statement

Both destination can be null and piece can be. The getColour() method returns an attribute of type Color from piece, which must be null if the piece is null. The piece at destination has a different pieceColour attribute then the one in the if-statement.

Specifically, how do I re-arrange (destination.getPiece() != null) ?

© Stack Overflow or respective owner

Related posts about java

Related posts about debugging