From: PJ Fanning Date: Thu, 7 Oct 2021 13:28:45 +0000 (+0000) Subject: [github-260] Check XDGFCell value for null to avoid NullPointerException. Thanks... X-Git-Tag: REL_5_2_0~440 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=36cf0e943e7a66f2f2fadd76bfd1c24a2d158c46;p=poi.git [github-260] Check XDGFCell value for null to avoid NullPointerException. Thanks to Dmitry Komarov. git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1893988 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFCell.java b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFCell.java index e4bdfcd8a5..2aef6b4c31 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFCell.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xdgf/usermodel/XDGFCell.java @@ -31,7 +31,7 @@ import com.microsoft.schemas.office.visio.x2012.main.CellType; * * The various attributes of a Cell are constrained, and are better defined in * the XSD 1.1 visio schema - * + * * Values of a cell are often the result of a formula computation. Luckily for * you, Visio seems to always write the result to the document file, so unless * the values change we don't need to recompute the values. @@ -39,9 +39,9 @@ import com.microsoft.schemas.office.visio.x2012.main.CellType; public class XDGFCell { public static Boolean maybeGetBoolean(Map cells, - String name) { + String name) { XDGFCell cell = cells.get(name); - if (cell == null) + if (cell == null || cell.getValue() == null) return null; if (cell.getValue().equals("0")) @@ -61,7 +61,7 @@ public class XDGFCell { } public static Integer maybeGetInteger(Map cells, - String name) { + String name) { XDGFCell cell = cells.get(name); if (cell != null) return parseIntegerValue(cell._cell); @@ -72,7 +72,7 @@ public class XDGFCell { XDGFCell cell = cells.get(name); if (cell != null) { String v = cell._cell.getV(); - if (v.equals("Themed")) + if (v == null || v.equals("Themed")) return null; return v; } @@ -80,6 +80,9 @@ public class XDGFCell { } public static Double parseDoubleValue(CellType cell) { + if (cell.getV() == null) { + return null; + } try { return Double.parseDouble(cell.getV()); } catch (NumberFormatException e) { @@ -91,6 +94,9 @@ public class XDGFCell { } public static Integer parseIntegerValue(CellType cell) { + if (cell.getV() == null) { + return null; + } try { return Integer.parseInt(cell.getV()); } catch (NumberFormatException e) { @@ -106,6 +112,9 @@ public class XDGFCell { * @return A value converted to inches */ public static Double parseVLength(CellType cell) { + if (cell.getV() == null) { + return null; + } try { return Double.parseDouble(cell.getV()); } catch (NumberFormatException e) {