Sunday, June 27, 2010

Perl and "booleans"

Note to self:

While the value of

$maybeBooleanResult = (2 == 2);

is

1

as would be expected, the value of

$maybeBooleanResult = (2 == 3);

is

''

rather than

0


This is not what I expected, and caused problems when I was writing code like

print "flag = $maybeBooleanResult\n";

Tuesday, May 11, 2010

Anand retains World Chess Championship title!


He did it! Anand Vishwanathan won the final round (12th) of his match against Veselin Topalov in a thrilling victory as Black (the first time Black won a game in this match, actually), to win the match 6.5-5.5, and retained his world championship title.

Congratulations to Anand for his strong play, and congratulations to both Anand and Topalov for putting on a great show to chess players around the world with their intense, ingenious, and entertaining games, in the best world championship match I have seen in years. Every game was hard-fought, with many implicit draw offers declined. This was one of the great matches in recent chess history.

The game itself started with Anand using the venerable Lasker Defense of the Queen's Gambit Declined, a very solid defense whose goal is to exchange off minor pieces and then free the Queen Bishop with either c5 or e5 to try to achieve equality. A typical late opening position arose after Black played 13...b6:


The plans for both sides are clear out of this opening. White is ahead in development, has more space, has an extra center Pawn (d-Pawn), and will try to pressure Black on the Queen side, especially hitting Black's c-Pawn on the half-open c-file by doubling up Rooks on it, etc. Black, on the other hand, is planning to play c5 and Bb7 to develop by fianchetto his remaining Bishop and make it a powerful force aiming toward White's center (and also King side) along the a8-h1 diagonal.

A few moves later, the character of the middle game became radically transformed:


Anand deliberately allowed himself an isolated c-Pawn in return for getting the Bishop over the Knight. I have to confess that in this position, even though it is equal, I would rather be Black. Black's Bishop can potentially get very powerful. White can try to make progress by trying to win the c-Pawn, but I like Black's Bishop.

The next stage of the game was interesting psychologically. Both sides maneuvered around, with Anand moving his Bishop all over the place, even repeating moves in an implicit offer of a draw. Obviously, he was trying to say to Topalov, "OK, the position seems equal, and I am happy to draw and have the match go to the rapid tie-break match, where I expect to do well, so if you want to win, you might as well vary and take a risk to try to win." Topalov indeed chose to vary, aiming his Rook and Knight at the Queen side, at the expense of moving pieces away from his King side, which is just what Anand wanted, of course! A critical position arose when Anand started an attack on Topalov's center and King side with 30...f5:


The position is still completely equal, and all Topalov had to do was defend his e-Pawn with 31 Nd2. Unfortunately, he decided to open up his own King side to Black's Bishop with 31 exf5? e4 32 fxe4?? Qxe4+ 33 Kh3:


And now, the game was all but over and lost! Unbelievable. I do not understand why Topalov did this. Even without calculating a lot of variations, it must be obvious that White has little to gain from this opening-up of his own King's position. He has a Rook and Knight at the other end of the board that are not useful defenders. The monster Bishop at a8 prevents White's King from ever getting back to g2. Meanwhile, g4 and h5 are completely unprotected and if Black's Queen landed on either square, it would be checkmate already! I can only think that Topalov truly feared going into the rapid playoff match, that he was as good as lost if he didn't complicate this twelfth game, at all costs.

The win for Black is not that easy to find, of course. It took many moves, but Anand did it (he missed several opportunities when he did not play the most decisive continuation, but from a practical point of view, he did not need to, because all he needed to do was find one sure way to win, not necessarily the shortest, possibly more complicated, one). There were a lot of tactical threats involving the perpetual threat of checkmating on g4, and eventually Anand forced the win of material and liquidation into a won endgame, and Topalov resigned:


A brilliant and effective winning attack by Anand, to cap off a fine world championship match!

Sunday, May 9, 2010

Anand-Topalov, Round 11

As White in round 11, the penultimate round of the match, Anand surprised me by using the English. Topalov entered the Reverse Dragon, as might be expected. Personally, I do not like allowing the Reverse Dragon as White. I don't think White gets any advantage, and in fact I'd rather be Black. As White I'd rather try to get some advantage in the opening. But I presume Anand wanted to play safe, and force the game into a slow, positional grind with little chance of wild complications from Topalov. He may have wanted to encourage Topalov to press too hard, and meanwhile he may have been perfectly happy with the plan of drawing his final White game, then drawing his final Black game, and winning the rapid tie-break playoff match. But what if by squandering a possible White win, he loses the match in the final game as Black? He must be pretty confident about holding the draw as Black.

In any case, Anand got into an inferior position as White in the game, gave up a Pawn in the ending, and only by being very precise held the draw as White. I would not have wanted my last game as White to have proceeded in this way. We shall see whether it was a mistake for Anand to go defensive in the late stages of this match.

Saturday, May 8, 2010

"Better player" vs. "one who wins"?

An interview with Kramnik about the Anand-Topalov match has had excerpts translated in English. Nothing he said is surprising or new, but I thought it would as good a time as any to revisit a serious philosophical question, which every sports fan or stock market trader grapples with regularly: in a competitive enterprise, what is the nature of the distinction between someone who is "better" and someone who "wins" often (the implication being that someone could "just" be "lucky")?

Kramnik says that Anand is the "better" player, while Topalov "still has good results even when he doesn't play well." This is a somewhat biased, provocative way of summarizing the objective reality of the records of these two fine, top-level chess players. With computer-aided analysis of chess moves that occur in a game, it is easy to note the number of moments when someone has made a move that is so "bad" that with perfect responses by the opponent, the player should lose where the game should not have been lost otherwise. For example, round 9 was an ideal example of a game in which Topalov repeatedly made errors such that if Anand had played perfectly, Topalov would have lost. This is one way of expressing what it means for someone to not play "well" but still achieve a good result (in this case, a draw). But this is a biased criterion, because one could also say that in this game, it was Anand who did not play "well", because he failed to win when he could have.

A more "objective" criterion could be, summarize the computer-scored evaluations of the positions after each player's moves, and see who has the smallest average evaluation score deviation from the computer's "best" move. By this criterion, Anand might come out the better player in this game, or might not (I have not bothered to do any such computation). But this criterion is still flawed. In many of the games in which Anand drew as Black with the Slav, his "average" deviation might still be lower than Topalov's, because of the use of the passive, defensive opening whose entire goal is to try to "safely" ensure a draw while clawing back from an inferior endgame the whole way; various opening moves would be penalized, even if after the opening phase, Anand started playing many perfect moves. To use a criterion of "deviation" blindly would be to violate the whole spirit of chess, which is that computer scores are not a reflection of some kind of Platonic reality but are a tool for driving choice of a move, a strategy; and different computer engines assign interestingly different scores to the same moves. Different openings result in a different rhythm of how Black deals with White's initial "advantage". Since chess is undoubtedly a draw with best play anyway, the numbers are only a reflection of how well one can see the rest of the game at a given point. Changing the computer's evaluation depth and time limit results in different numbers.

In the end, chess is a sport, a "struggle", as David Bronstein put it. To speak of someone being a "better" player outside the context of proved competitive results again and again does not make sense. Kramnik knows this, of course, so what he is really saying is simply that he prefers to play in a particular way, minimizing the risk of forced loss (against any competitor, including a computer), while Topalov is willing to achieve good results by whatever means necessary, including being more physically and emotionally resilient, playing "bad" moves in order to confuse his human component and hope to swindle a draw or win, avoiding getting into time trouble. This is all part of the struggle.

All of us who play chess know this. I cannot count how many games I have won even though I "should" not have, simply because I stubbornly played on in a lost position and swindled a win. I also cannot count how many games I have lost even though I was winning the whole way and then made errors. Kramnik is basically implying that somehow there should be a notion of "justice" in the chess universe, such that there should be a limit to how much one gets "lucky", and somehow players like Topalov get "lucky" more than they should. I think he is in error in implying that there has to be this notion of justice. Was it fair that the dinosaurs went extinct on the earth while tiny little mammals survived what is thought to have been an asteroid collision? The question does not objectively make that much sense.

My final comment is that I personally prefer the Kramnik or Anand style of chess play to Topalov's. I did not always have this preference, but I grew into it. My best argument for my preference is simply that years ago, when I began appreciating it and adopting it in my own play (toning down the speculative attacks), I not only improved my results but also improved my enjoyment and "understanding" of chess.

There are two more rounds to go for Anand-Topalov. I hope Anand accepts the Nimzo-Indian challenge again as White.

Friday, May 7, 2010

Anand-Topalov, Round 10

Round 10 of the world chess championship match featured Topalov as White against Anand. As I predicted, Anand varied away from the Slav. However, I had not predicted that he would return to the Grünfeld, which he did use in round 1. Anand deviated first, avoiding the variation with 10...Na5 that had deflected his Knight away from the center and left his King vulnerable to Topalov's attack. Instead, Anand just developed normally while Topalov also developed normally, building up the classic center, resulting in a typical position:


The typical Grünfeld game, when it does not erupt in White embarking on a sacrificial attack on Black's King (which is no longer protected by a Knight because it was exchanged early on c3), winds up going into an endgame dictated by both sides' Pawn structures. White's advantage is having the center d-Pawn and center e-Pawn, particularly the d-Pawn, which Black lacks and therefore can often be pushed all the way to d8, possibly with an exchange of both sides' e-Pawns along the way. The d-Pawn is so key that it was given a mnemonic nickname, "Delroy", by Jonathan Rowson in his wonderful book Understanding the Grünfeld (which I can't believe is out of print at the moment of this post).

Black's advantage is the Queen side majority of the a-Pawn and b-Pawn against White's lone a-Pawn. White's Queen side is loose and weak because of not having a b-Pawn or c-Pawn. Black may end up pushing the b-Pawn all the way.

Topalov quickly got things going by committing to 15 d5, an advance of Delroy. After some inaccuracy by Anand, Topalov got an advantageous position and Anand chose to bail out into an inferior but drawable endgame:


One of the pleasures and mysteries of chess is how one can very often look at a real position and know instantly what opening was played. Here, with Delroy on d5, who would not guess that a Grünfeld was played? The problem in this particular position is that White has the two Bishops. Black has to be very careful not to let a breakthrough happen to either his Queen side Pawns or King side Pawns. As it turned out, Anand defended very well, and after some inaccuracy by Topalov, made the drawn outcome clear by the time this position was achieved:


White has gotten nowhere on the King side, White's King is centralized but has nowhere else to go, Black has blockaded Delroy with his Bishop on d6, Black's a-Pawn and b-Pawn are safely advanced, and finally, White's dark-squared Bishop is completely neutralized by Black's dominating Knight. After Anand's 48...Ba3, trading off that Bishop, the draw was obvious, because he could (and did) go for either White's a-Pawn or d-Pawn to liquidate all of White's winning chances.

The slightly weird thing to me is how Topalov seems to let his Bishops get pushed back to passivity by Knights. We saw this position in round 5:


These kinds of positions were never forced on Topalov. He entered them voluntarily despite their inferiority. Strange. I wonder whether he has been told about his habit, and whether Anand knows about it.

In any case, the match is still tied, and since Anand defended in this game without trouble, I think Topalov's momentum is stopped, and I give them fully even chances for the title. There are only two regular games left, and then if the match is still tied,  there is a tie-break match of rapid games. Now Anand has a fierce reputation for rapid chess, so perhaps if it comes to a tie-break, he has the advantage, but I don't know if that is necessarily the case. They wouldn't be playing a fresh rapid match, but would be playing it after being fatigued from twelve regular games. I don't know who would be more fatigued. So I wouldn't make any predictions right now.

Thursday, May 6, 2010

Anand-Topalov, Round 9

I expected Round 9 to be a tough fight, because with the match tied so far, and only four more rounds to go, there were not many more chances to play hard for a win.

As I suspected he might, Anand gave up on the Catalan and decided to invite the Nimzo-Indian, and Topalov took him up on the challenge. The Nimzo-Indian is a good choice for either White or Black to play for a win, because in almost all variations, there are clear imbalances, primarily of White obtaining the Bishop pair and Black having a sounder Pawn structure. Anand played the classic Rubinstein variation, and Topalov played what I suppose we could call the Karpov variation, simply because Karpov made it his primary defense as Black back in the day.

The following thematic position arose out of the opening:


But in the space of a few moves, Anand "allowed" Topalov to obtain a very unusual middlegame, in which Topalov gave up his two Rooks for Anand's Queen:


What is important to realize is that even though your favorite chess engine (I prefer Rybka and Stockfish) might think the game is now dead equal, in the hands of human beings, there is a huge amount of play left. Also, personally I would much rather be White in this kind of position, because I think it is White's game to lose. Two Rooks, if made to work together, would be much more dangerous against the opponent's King than one Queen. On the other hand, one Queen can be very effective in forcing a draw with perpetual check, if the opponent's King is too exposed. Therefore, if I were White, I would try to get my pieces to work together (not get accidentally forked or something by the Queen) and checkmate Black, while keeping my King safe. Black's practical task is much harder. Black's only way to win, really, is to somehow create a Queenside passed Pawn and promote it. In other words, whereas White to win has to finish Black off before an endgame happens (by checkmating or by winning material as a result of checkmating threats), Black to win has to protect the King and reduce White's checkmating capabilities and enter an endgame in which somehow Queening the a-Pawn or b-Pawn occurs. These are the structural constraints implied by this position.

The following position, only a few moves after the Queen/Rooks trade above, illustrates more starkly the dangers for both sides:


Both sides have played well, and Black is trying to trade off White's dangerous two Bishops, and also is aggressively aiming his Queen at White's isolated a-Pawn and d-Pawn. Note that Black's aggression with the Queen does leave his King less well defended, however.

After some less than perfect play, in which Topalov mistakenly grabbed White's d-Pawn, the following position arose:


At this point, Anand started going astray, undoubtedly partly because of time pressure. He may have felt (correctly) that the win was within his grasp, but could not decide how to follow through. Instead of something like 33 Nxe6 (followed by f4) or the "obvious" 34 Rc8+ (followed by Rec1), he played the terrible 33 Ne4, allowing Topalov to painlessly take the a-Pawn, and a new phase of the game began, in which Black's King was still in danger, but Black also has a connected pair of passed Pawns, that given a huge amount of time, could become a Queening threat.

Sadly, in the rest of the game, Anand repeatedly could not find the best moves at many points (one has to understand how many hours this game took to complete, and how the burden of proof of the win always lay with White), Topalov repeatedly made some blunders that should have resulted in a loss, and finally, the game was drawn, by perpetual check.

Here is one of the won positions Anand had (in which Topalov had sacrificed a Knight for swindling possibilities):


Anand seemed at a loss in this position, and in time pressure and probably extreme fatigue, shuffled his Rooks around, allowing Topalov to keep on pushing his Pawns, until Anand had to give up his Knight for the Queened b-Pawn, and then when he won the a-Pawn by taking with the wrong Rook (!), the position was a dead draw with obvious perpetual checks on White's King, which has no hiding place:


A very tiring and exciting game! Much could be said about the errors by both players, but these wide-open positions with two Rooks against a Queen are extremely difficult for human beings (with constraints of time and energy) to calculate out perfectly. Computers can "see" the truth of these positions in a split second, but what we're watching is human chess, not computer chess.

So, three more rounds to go. I stand by my assertion (before this round) that Topalov has an advantage. Anand cannot be feeling happy that he expended so much energy failing repeatedly to find a win in won positions, and he has only one White left. Topalov must be unhappy that he repeatedly played losing moves, but he got his draw, after all, and has two Whites left, so I would expect that he is less unhappy than Anand. What next? I imagine that Topalov would be pleased to try again to smother Anand's Slav defense, since he succeeded the last time. Furthermore, Anand may feel that he needs to get out of his "passive as Black" mode anyway, and avoid the Slav. It would be very exciting, but risky, if Anand decided to play the Semi-Slav and allow Topalov to go into the Anti-Moscow gambit. Or perhaps he too could go for a dynamic Nimzo-Indian or Queen's Indian? One thing I'm fairly confident of: Topalov will try to play some kind of gambit in the next round against whatever Anand plays!

Tuesday, May 4, 2010

Anand-Topalov, Rounds 5-8

We've reached another critical point in the Anand-Topalov world chess championship match. The match is now tied, at 4-4, and there are only four more rounds left.

In round 5, Topalov as White played into Anand's Slav for the second time, trying to squeeze out an endgame advantage from the opening. Anand varied with 15...h5 instead of 15...h6 from round 3. Topalov achieved some advantage, but a tactic allowed Anand to equalize immediately, and the game ended in a draw. Despite the outcome, the fact that Topalov was willing to play on Anand's turf, rather than vary the opening, seemed to show Topalov's determination and confidence.

Round 6 had Anand as White use the Catalan yet again. Topalov returned to the variation he had used in round 2, but Anand varied with 10 Bg5. Topalov gave back a Pawn to achieve a curious Queenless middlegame in which White had two Knights and Black had two Bishops. Topalov then played aggressively but the draw was a logical outcome at the end, and it occurred. After rounds 5 and 6, Topalov was probably not feeling bad, because despite not winning either game, in two games he had managed to find ways to try for a win while Anand had the more passive positions.

Round 7 was extremely complicated. Anand used the Catalan again, but Topalov countered with a sacrificial line that got Anand thinking. In a very tense game, in which the computers might know it should be a draw, but humans could easily go astray, both players implicitly declined and offered threefold repetitions and played for a win until the draw was clear. Wow. By now, Topalov must have been pretty happy, because of how he had not only neutralized Anand's Catalan twice in a row as Black, but also had played more and more aggressively against it.

Finally, round 8 came. This time, Topalov invited Anand's Slav again, and Anand varied, but soon after he played 20...f5 for counterplay, he got into a bad position. Eventually, an opposite-colors-Bishop ending came about, but Topalov kept on pressing, until Anand blundered and summarily resigned! Wow.

From my point of view, Anand's 20...f5, even if objectively OK, was probably a psychological error. In the past Slav games, Anand had contented himself with safe, non-weakening, passive defense to draw. I imagine that Anand started losing patience and embarked on the faulty plan that included 22...f4? and then got thrown off after that. Topalov completely won this psychological battle. In fact, the last four games all had Topalov putting considerable pressure on Anand. Even without this win, I would feel that Topalov already had the psychological edge by now (even with a point behind). Now, I consider that Anand is in serious trouble, even with the score being a 4-4 tie. Topalov has a record of coming back from behind. He has proved in the last four games that he is capable of creating complications and aggression whether as White or as Black. If Anand just makes one more big error, I think he is through. I have to wonder whether he has run out of Catalan ideas as White and needs to do something different. And I have to wonder whether all the passive play as Black in the Slav is really to his taste. We'll have to see whether he tries to vary (either as White or as Black) in the remaining games of the match.

Wednesday, April 28, 2010

Anand-Topalov Round 4

Today was round 4 of Anand-Topalov, and it was very exciting! Anand used the Catalan again, and Topalov tried yet another c4 Pawn-grabbing variation (interestingly, a variation that he used against Kramnik in their world championship match in 2006), but out of a very complicated position, Anand found a nice sacrifice (23 Nxh6+) that invaded Topalov's insufficiently protected King (Black had only one Rook in the King side, while a Queen, Rook, two Knights, and a Bishop were all in the Queen side!) and quickly forced a win. Wow, what a game! Who said the Catalan is a boring opening leading to boring games?

It must be painful being Topalov right now. His attempts at creating unbalanced complications out of a Catalan as Black by playing Pawn-grabbing variations have so far not succeeded in his favor. We shall see how he tries to stop Anand's momentum in the upcoming rounds.

Tuesday, April 27, 2010

World Chess Championship: Anand-Topalov 1.5-1.5 so far after 3 rounds

I thought I'd share a few thoughts I've had on the 2010 FIDE World Chess Championship match currently in progress.

There are plenty of blogs out there with analysis of the moves of the games themselves, as well as passionate commentary by fans. I would like to offer my own narrative, on the psychology of the match, and maybe some predictions as well. I will not offer any original detailed move analysis, since many others have done a fine job with that: one good source is Dennis Monokroussos's blog.

Before the match began, I felt that the end result would be fairly close, most likely with Anand Viswanathan of India emerging victorious over Veselin Topalov of Bulgaria. I still stand by this prediction.

The Anand-Topalov match is now tied so far at 1.5-1.5, after a hair-raising first round in which Anand lost as Black, then a fascinating second round in which Topalov lost as Black, then a draw in the third round. So far, the match has been exciting, with real battles at the board. The fourth round will have Anand as White against Topalov.

Both Anand and Topalov are, of course, great players. While Topalov is a fierce fighter and has no fear of sacrificing material and creating immense complications, Anand is more cautious, but also more versatile in style. I think his versatility gives him a slight edge.

The first game had Anand, as Black, fall victim, in horrific manner, to deep tactical preparation that Topalov rattled off quickly. Topalov played a known Pawn sacrifice against Anand's Grünfeld, then simply launched an attack against Anand's King, and in one move, Anand made a blunder (23...Kf7??) then ended the game, because of the sacrifice (24 Nxf6!) which simply blasts Black's position apart and allow White's Rook to go to h3 and down the h file, and the other Rook to go down the c file, while the Queen and Bishop come in as well. It was a shocking way for the first game to end.

After this disastrous first game, I wondered whether Anand could bounce back. He did, and what impressed me was the way in which he did it, almost as though he hadn't just a day earlier walked into one of the shortest game losses in world championship history. This is, of course, what all competitive professionals can and must do: not dwell on the past, but move forward.

The second game had Anand playing White. Topalov played 3...d5, probably with the intention of inviting a sharp Vienna or Ragozin, but Anand played the Catalan. This was a revealing choice. Clearly Anand was aiming at a positional squeeze against Topalov. That he succeeded so well, I think, reflects Topalov's weaknesses more than the first game reflected Anand's. The single most interesting moment in the match so far took place when Anand played the strange 15 Qa3, after having sacrificed the d4 Pawn earlier for positional compensation. This move, which looks so bizarre and ugly, even to a beginner's eye, must have been, if nothing else, psychologically motivated. Exchanging Queens and even incurring doubled Pawns, was a courageous attempt (which succeeded) at unbalancing Topalov's mind. We all know that Topalov does not like to be on the defensive or engaged in dry, positional play. By forcing Topalov into this kind of game, Anand reminded me of how different human chess is from computer chess. Yes, everyone can easily see that Qa3 is "objectively" not the best move to play, and everyone these days can fire up Rybka or some other computer engine to (rightfully) declare Black to have an advantage in the ensuing Queenless middlegame, but the computer engines do not know that Topalov does not like this kind of game and has a hard time finding a plan, and is tempted to start lashing out, playing weakening moves, and then suddenly trying for tactical counterplay where it is unwarranted. Unfortunately, Topalov did exactly what he was prone to doing, and lost the game suddenly after Anand simply played reasonable moves, maintaining pressure, and then simplifying to a trivially won Rook and Pawn ending. Anand played like a Kramnik in this game, demonstrating his versatility. We have to recall that in his match against Kramnik in 2006, he surprised Kramnik with Topalov-like aggressive opening preparation, coming up with novel tactical play against Kramnik, both as White (avoiding a trade of Queens in the classical Nimzo-Indian and pushing h3 and g4 to drive Kramnik's Queen back) and as Black (with his ultra-sharp theoretical novelty 14...Bb7 in the old Meran). So Anand can play like Topalov and he can play like Kramnik. I think this gives him an advantage, although he has a weakness of sometimes becoming cautious and not scoring a point in a game.

The third game, played today, ended as a draw, a high-quality game without any errors by either Anand or Topalov. I consider this game, however, to have been a continuation of Anand's momentum. First of all, he was Black, so holding a draw was a decent accomplishment. Second, the psychological reality is that he drew using a defensive variation of the Ne5 Slav that Kramnik had rehabilitated, using it against Topalov in 2006! I wonder what Topalov thought of Anand playing yet again like Kramnik. Topalov grabbed a lot of space with Pawn lunges such as h5 and a5, b4, but could make no headway while Anand caught up on rearranging his pieces. Now, I wonder whether Topalov will, the next time he is White, revert to ideas in the slow e3 Slav that he had unleashed earlier in his match with Kramnik! There, at least, was the imbalance of Bishop versus Knight to work with in the middlegame.

Now, to the fourth game coming up: will Anand play the Catalan again in the fourth game, or something completely different? Will he allow the Nimzo-Indian? Or will Topalov vary before that? I do not believe we will see Topalov take such a risk as play the Modern Benoni or the King's Indian, but who knows? This has been a fun match so far to watch, and I hope it continues to be stimulating. I wonder what psychological tricks Topalov will try to use to disturb Anand's mind.

Friday, January 8, 2010

Java autobox pitfall

I just wasted time figuring out a mysterious java.lang.NullPointerException thrown by a program I'm working on, because my Java coding standards result in my almost never getting a NullPointerException. I was calling a method that I didn't write (generated by JAXB that had the type signature

boolean isGood()

and assumed that this should have been a simple check of an attribute.

Looking at the generated code, I saw that it looked like


public boolean isGood() {
return good;
}


and was therefore puzzled, until I saw that good was not what I thought it was, a boolean, but rather

protected Boolean good;

Aha, autoboxing and unboxing! Of course, what was happening was that the Boolean instance variable good was uninitialized, and therefore null, and therefore the unboxing failed. This was unintuitive behavior to me, because it would be more sensible if for a Boolean, null were treated as converting to boolean value of false.

Or perhaps that way lies madness, and it's good that Java didn't turn into Perl with "smart" implicit conversions.

Anyway, what annoyed me was that just looking at the signature of boolean isGood(), I was misled. Clearly, JAXB should have generated Boolean getGood() instead, in order to make explicit the fact that it was handling a three-value variable instead of two.