mirror of https://github.com/apache/poi.git
Fix bug #56450 - Avoid a NPE if a comment has no associated NoteRecord (but we still don't know where it belongs)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1589770 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
ed23692537
commit
2c018cc43a
|
@ -16,8 +16,18 @@
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
package org.apache.poi.hssf.usermodel;
|
package org.apache.poi.hssf.usermodel;
|
||||||
|
|
||||||
import org.apache.poi.ddf.*;
|
import org.apache.poi.ddf.DefaultEscherRecordFactory;
|
||||||
import org.apache.poi.hssf.record.*;
|
import org.apache.poi.ddf.EscherBSERecord;
|
||||||
|
import org.apache.poi.ddf.EscherContainerRecord;
|
||||||
|
import org.apache.poi.ddf.EscherOptRecord;
|
||||||
|
import org.apache.poi.ddf.EscherProperties;
|
||||||
|
import org.apache.poi.ddf.EscherSimpleProperty;
|
||||||
|
import org.apache.poi.hssf.record.CommonObjectDataSubRecord;
|
||||||
|
import org.apache.poi.hssf.record.EndSubRecord;
|
||||||
|
import org.apache.poi.hssf.record.NoteRecord;
|
||||||
|
import org.apache.poi.hssf.record.NoteStructureSubRecord;
|
||||||
|
import org.apache.poi.hssf.record.ObjRecord;
|
||||||
|
import org.apache.poi.hssf.record.TextObjectRecord;
|
||||||
import org.apache.poi.ss.usermodel.Comment;
|
import org.apache.poi.ss.usermodel.Comment;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -211,6 +221,15 @@ public class HSSFComment extends HSSFTextbox implements Comment {
|
||||||
protected NoteRecord getNoteRecord() {
|
protected NoteRecord getNoteRecord() {
|
||||||
return _note;
|
return _note;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Do we know which cell this comment belongs to?
|
||||||
|
*/
|
||||||
|
public boolean hasPosition() {
|
||||||
|
if (_note == null) return false;
|
||||||
|
if (getColumn() < 0 || getRow() < 0) return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setShapeType(int shapeType) {
|
public void setShapeType(int shapeType) {
|
||||||
|
|
|
@ -28,7 +28,20 @@ import org.apache.poi.hssf.model.DrawingManager2;
|
||||||
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
import org.apache.poi.hssf.model.HSSFFormulaParser;
|
||||||
import org.apache.poi.hssf.model.InternalSheet;
|
import org.apache.poi.hssf.model.InternalSheet;
|
||||||
import org.apache.poi.hssf.model.InternalWorkbook;
|
import org.apache.poi.hssf.model.InternalWorkbook;
|
||||||
import org.apache.poi.hssf.record.*;
|
import org.apache.poi.hssf.record.AutoFilterInfoRecord;
|
||||||
|
import org.apache.poi.hssf.record.CellValueRecordInterface;
|
||||||
|
import org.apache.poi.hssf.record.DVRecord;
|
||||||
|
import org.apache.poi.hssf.record.DimensionsRecord;
|
||||||
|
import org.apache.poi.hssf.record.DrawingRecord;
|
||||||
|
import org.apache.poi.hssf.record.EscherAggregate;
|
||||||
|
import org.apache.poi.hssf.record.ExtendedFormatRecord;
|
||||||
|
import org.apache.poi.hssf.record.NameRecord;
|
||||||
|
import org.apache.poi.hssf.record.NoteRecord;
|
||||||
|
import org.apache.poi.hssf.record.Record;
|
||||||
|
import org.apache.poi.hssf.record.RowRecord;
|
||||||
|
import org.apache.poi.hssf.record.SCLRecord;
|
||||||
|
import org.apache.poi.hssf.record.WSBoolRecord;
|
||||||
|
import org.apache.poi.hssf.record.WindowTwoRecord;
|
||||||
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
|
import org.apache.poi.hssf.record.aggregates.DataValidityTable;
|
||||||
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
import org.apache.poi.hssf.record.aggregates.FormulaRecordAggregate;
|
||||||
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
import org.apache.poi.hssf.record.aggregates.WorksheetProtectionBlock;
|
||||||
|
@ -2115,7 +2128,7 @@ public final class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet {
|
||||||
}
|
}
|
||||||
if (shape instanceof HSSFComment) {
|
if (shape instanceof HSSFComment) {
|
||||||
HSSFComment comment = (HSSFComment) shape;
|
HSSFComment comment = (HSSFComment) shape;
|
||||||
if (comment.getColumn() == column && comment.getRow() == row) {
|
if (comment.hasPosition() && comment.getColumn() == column && comment.getRow() == row) {
|
||||||
return comment;
|
return comment;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2549,4 +2549,20 @@ public final class TestBugs extends BaseTestBugzillaIssues {
|
||||||
assertAlmostEquals(1950, s.getColumnWidth(10), fontAccuracy);
|
assertAlmostEquals(1950, s.getColumnWidth(10), fontAccuracy);
|
||||||
assertAlmostEquals(2225, s.getColumnWidth(11), fontAccuracy);
|
assertAlmostEquals(2225, s.getColumnWidth(11), fontAccuracy);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void bug56450() {
|
||||||
|
HSSFWorkbook wb = openSample("56450.xls");
|
||||||
|
HSSFSheet sheet = wb.getSheetAt(0);
|
||||||
|
int comments = 0;
|
||||||
|
for (Row r : sheet) {
|
||||||
|
for (Cell c : r) {
|
||||||
|
if (c.getCellComment() != null) {
|
||||||
|
assertNotNull(c.getCellComment().getString().getString());
|
||||||
|
comments++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assertEquals(0, comments);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
Loading…
Reference in New Issue