Maybe this should be titled … why you should check your examples thoroughly.
A few days ago I posted a Groovy code fragment here and said I was having trouble with the same code on an application.
My problem was that the application was a piece of coursework and I really did not want to post that here in case there was some sort of plagiarism issue later on. So I wrote a code fragment that, I thought, encapsulated the problem.
I then also took the issue to the groovy-user mailing list – see here.
The problem, though, was that there was a subtle difference between the two examples and so I was not asking people to test the same thing.
My problem was that I wanted people to enter a string of two integers separated by a comma but that the
String.tokenize() method was failing to parse the input string correctly (or so I thought).
In reality the core issue was that the
Scanner object (in the real code but not in the test example) was already tokenizing the input string.
To make matters worse, though, my code example was failing, but in a different way, on my Ubuntu machine – though it does not any more now I have upgraded Groovy from 1.7.0 to 1.7.6 – as the screenshot below shows – this may or may not be a bug in the code installed by default with Ubuntu so beware:
Anyway, the fundamental issue was the
Scanner and not the tokenize message.