https://bz.apache.org/bugzilla/show_bug.cgi?id=58002
Bug ID: 58002
Summary: EscherAggregate.createAggregate doesn't always read
NoteRecord
Product: POI
Version: 3.12-FINAL
Hardware: PC
Status: NEW
Severity: normal
Priority: P2
Component: HSSF
Assignee: [email protected]
Reporter: [email protected]
Created attachment 32793
--> https://bz.apache.org/bugzilla/attachment.cgi?id=32793&action=edit
Sample code to read comments.
I have this XLS file that when I attempt to retrieve all HSSFComment via
worksheet's drawing patriarch's children, I get a NullPointerException when I
attempt to get the comment's column (and row). The _note component didn't get
initialized. I have tracked this issue down to:
org.apache.poi.hssf.record.EscherAggregate.createAggregate, near line 442:
// any NoteRecords that follow the drawing block must be aggregated and
and saved in the tailRec collection
while (loc < records.size()) {
if (sid(records, loc) == NoteRecord.sid) {
NoteRecord r = (NoteRecord) records.get(loc);
agg.tailRec.put(r.getShapeId(), r);
} else {
break;
}
loc++;
}
If the current loc points to a record where the sid is NOT NoteRecord, the loop
exits without checking additional records. In my test file, the next record is
a DrawingSelectionRecord [MSODRAWINGSELECTION] with sid 237 (0xED). The fix
that works for my document is to remove the else break, as in:
// any NoteRecords that follow the drawing block must be aggregated and
and saved in the tailRec collection
while (loc < records.size()) {
if (sid(records, loc) == NoteRecord.sid) {
NoteRecord r = (NoteRecord) records.get(loc);
agg.tailRec.put(r.getShapeId(), r);
}
loc++;
}
This code change seems without side effects because loc is not referenced
anymore in the method.
Attached is my document that causes this error. I tried changing the pictures
or adding new comments, and it ends up rewriting the file in such a way that
there's no error. So I have it in the original form. (The pictures come from
Windows 7 sample pictures). The document is currently 1.6 MB and might be too
large to upload.
Also attached is a simple program (Java 8) to read the file comments:
Expected output (when I use the debugger to change loc to the next value before
testing if it's a NoteRecord):
Robert Kish:
Yo!: 0,2
Robert Kish:
2nd note!: 1,2
Robert Kish:
Woah!: 22,45
Robert Kish:
Woah top!: 21,0
Actual output:
Robert Kish:
Yo!: Exception in thread "main" java.lang.NullPointerException
at
org.apache.poi.hssf.usermodel.HSSFComment.getColumn(HSSFComment.java:184)
at NoteTest.main(NoteTest.java:26)
Thank you.
--
You are receiving this mail because:
You are the assignee for the bug.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]