Wednesday, January 13, 2010

Strange behaviour of while on linux

Last night I had I strange fight with java on linux. I tried to unzip a zip archive with with something like

zipEntry = zipStream.getNextEntry();
   // unzip
} // end while

This worked like a charm on windows but on linux the vm left the while loop, although, proveable, zipEntry was not null.

I changed the loop to

while ( (zipEntry=zipStream.getNextEntry()) != null)

and now it works on linux too. I feel completely confused about this behaviour. Maybe I should open a bug, as I can reproduce it with a large zip stream. In the meantime I learned a lot about encoding troubles with zip archives, and that the ant zip task doesn't use but it's own implementation that doesnt encode filenames with UTF-8 on windows like does.

No comments: