It seems to me that the number of cell comments that can be added to a spreadsheet using HSSF without messing up the ordering is limited to 65536 comments.
* Create sheet with comments using HSSFComment
* write sheet to output stream
* read sheet with input stream
-> comments do not appear in correct row/col anymore
NOTE: MS-Excel can read the comments correctly!!
The HSSFCell.findComments() method hashes TextObjectRecords with their Short datatype IDs, which explains the number limit. Using Integer here (and when serializing/deserializing) messes up the format so that not even MS-Excel can read it.
Attachment:
provides JUnit test file that produces a spreadsheet with more than 65536 comments, writes to a file, reads the file in again and compares the order of comments between the two sheets.
Comments contain just row/col index numbers for comparison with cell content.

Ken,
Thanks for the good bug report, you've done 50 percent of the job to fix the problem. I committed the fix in r782398.
ShapeId is unsigned short and matching cells and comments by it works fine only if the number of comments is less than 65536. The fact that Excel can handle sheets with greater numbers of comments made me think it uses a different logic. In fact, Excel uses a simple ordinal relationship: i-th NoteRecord corresponds to the i-th drawing group containing TextObjectRecord with the comment's text. This heuristics works fine for any number cell comments.
Regards,
Yegor

This is ASF Bugzilla: the Apache Software Foundation bug system. In case
of problems with the functioning of ASF Bugzilla, please contact
bugzilla-admin@apache.org.
Please Note: this e-mail address is only for reporting problems
with ASF Bugzilla. Mail about any other subject will be silently
ignored.