Le 24/04/2010 22:19, Philip a écrit :
Hi there,
(jOpenDocument 1.2.b3)
1. When I create a new sheet using sh.addSheet () and then invoke
sh.ensureColumnCount(),
the last method always fails the *first* time with a null pointer
error message. Just trying the same method with the same arguments
again (using a try-catch construct) makes the method work.
Uninitialized data or pointers somewhere?
BTW I don't see this behaviour on existing sheets.
That was caused by the method not handling the lack of styles. I've attached a patch that should
fix the issue.
2. When creating a sheet using addSheet, followed by invoking
ensureColumnCount (twice, see above), trying to add data (e.g., a 100
rows x 1024 columns numerical array) fails.
If I try-catch each sh.getCellAt().setValue() method, in the end I get
a 100 rows by 1024 columns sheet, but the upper row only contains 1
single cell at A1. Trying to access the next cells (at B1, C1, ...)
always fails with java errors ("out of bound").
All the other rows (A2:AMJ1024) are complete and look good, however.
Perhaps this one is related to the first bug (above).
Yes, after ensureColumnCount() throws the NPE the data isn't valid
anymore.
HTH,
Sylvain
--
Subscription settings:
http://groups.google.com/group/jopendocument/subscribe?hl=en
Index: src/org/jopendocument/dom/StyledNode.java
===================================================================
--- src/org/jopendocument/dom/StyledNode.java (revision 8382)
+++ src/org/jopendocument/dom/StyledNode.java (working copy)
@@ -61,14 +61,18 @@
* Assure that this node's style is only referenced by this. I.e. after
this method returns the
* style of this node can be safely modified without affecting other nodes.
*
- * @return this node's style.
+ * @return this node's style, never <code>null</code>.
*/
public final S getPrivateStyle() {
final S currentStyle = this.getStyle();
- if (currentStyle.isReferencedAtMostOnce())
+ if (currentStyle != null && currentStyle.isReferencedAtMostOnce())
return currentStyle;
- final S newStyle =
this.styleClass.getStyleClass().cast(currentStyle.dup());
+ final S newStyle;
+ if (currentStyle == null)
+ newStyle =
this.styleClass.createAutoStyle(getODDocument().getPackage());
+ else
+ newStyle =
this.styleClass.getStyleClass().cast(currentStyle.dup());
this.setStyleName(newStyle.getName());
// return newStyle to avoid the costly getStyle()
assert this.getStyle().equals(newStyle);
Index: src/org/jopendocument/dom/spreadsheet/Column.java
===================================================================
--- src/org/jopendocument/dom/spreadsheet/Column.java (revision 8382)
+++ src/org/jopendocument/dom/spreadsheet/Column.java (working copy)
@@ -36,8 +36,9 @@
super(parent.getODDocument(), tableColElem, ColumnStyle.class);
}
- public final float getWidth() {
- return this.getStyle().getWidth();
+ public final Float getWidth() {
+ final ColumnStyle style = this.getStyle();
+ return style == null ? null : style.getWidth();
}
public final void setWidth(final Number w) {
Index: src/org/jopendocument/dom/spreadsheet/ColumnStyle.java
===================================================================
--- src/org/jopendocument/dom/spreadsheet/ColumnStyle.java (revision 8382)
+++ src/org/jopendocument/dom/spreadsheet/ColumnStyle.java (working copy)
@@ -38,8 +38,9 @@
super(pkg, tableColElem);
}
- public final float getWidth() {
- return
ODFrame.parseLength(getFormattingProperties().getAttributeValue("column-width",
this.getSTYLE()), TableStyle.DEFAULT_UNIT);
+ public final Float getWidth() {
+ final String attr =
getFormattingProperties().getAttributeValue("column-width", this.getSTYLE());
+ return attr == null ? null : ODFrame.parseLength(attr,
TableStyle.DEFAULT_UNIT);
}
public final String getBreakBefore() {
Index: src/org/jopendocument/dom/spreadsheet/Table.java
===================================================================
--- src/org/jopendocument/dom/spreadsheet/Table.java (revision 8382)
+++ src/org/jopendocument/dom/spreadsheet/Table.java (working copy)
@@ -473,13 +473,25 @@
private void updateWidth(final boolean keepTableWidth) {
final Float currentWidth = getWidth();
float newWidth = 0;
+ Column<?> nullWidthCol = null;
// columns are flattened in ctor: no repeated
- for (final Column col : this.cols) {
- newWidth += col.getWidth();
+ for (final Column<?> col : this.cols) {
+ final Float colWidth = col.getWidth();
+ if (colWidth != null) {
+ assert colWidth >= 0;
+ newWidth += colWidth;
+ } else {
+ // we cannot compute the newWidth
+ newWidth = -1;
+ nullWidthCol = col;
+ break;
+ }
}
// remove all rel-column-width, simpler and Spreadsheet doesn't use
them
// SpreadSheets have no table width
if (keepTableWidth && currentWidth != null) {
+ if (nullWidthCol != null)
+ throw new IllegalStateException("Cannot keep width since a
column has no width : " + nullWidthCol);
// compute column-width from table width
final float ratio = currentWidth / newWidth;
// once per style not once per col, otherwise if multiple columns
with same styles they
@@ -493,10 +505,17 @@
}
} else {
// compute table width from column-width
- if (this.getStyle() != null)
- this.getStyle().setWidth(newWidth);
+ final TableStyle style = this.getStyle();
+ if (style != null) {
+ if (nullWidthCol != null)
+ throw new IllegalStateException("Cannot update table width
since a column has no width : " + nullWidthCol);
+ style.setWidth(newWidth);
+ }
for (final Column<?> col : this.cols) {
- col.getStyle().rmRelWidth();
+ final ColumnStyle colStyle = col.getStyle();
+ // if no style, nothing to remove
+ if (colStyle != null)
+ colStyle.rmRelWidth();
}
}
}