]> source.dussan.org Git - poi.git/commitdiff
[bug-65227] add NPE guard in SheetUtil. Thanks to Petr Blaha
authorPJ Fanning <fanningpj@apache.org>
Fri, 9 Apr 2021 08:21:13 +0000 (08:21 +0000)
committerPJ Fanning <fanningpj@apache.org>
Fri, 9 Apr 2021 08:21:13 +0000 (08:21 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1888553 13f79535-47bb-0310-9956-ffa450edef68

poi/src/main/java/org/apache/poi/ss/util/SheetUtil.java

index 06d3aa1f70d7a0cc74aa0a79fb9acc3dbe66311e..5033e8ec85ad2d0f9e76040879315b4f2e6dbe4a 100644 (file)
@@ -160,18 +160,20 @@ public class SheetUtil {
         double width = -1;
         if (cellType == CellType.STRING) {
             RichTextString rt = cell.getRichStringCellValue();
-            String[] lines = rt.getString().split("\\n");
-            for (String line : lines) {
-                String txt = line + defaultChar;
+            if (rt != null && rt.getString() != null) {
+                String[] lines = rt.getString().split("\\n");
+                for (String line : lines) {
+                    String txt = line + defaultChar;
 
-                AttributedString str = new AttributedString(txt);
-                copyAttributes(font, str, 0, txt.length());
+                    AttributedString str = new AttributedString(txt);
+                    copyAttributes(font, str, 0, txt.length());
 
-                /*if (rt.numFormattingRuns() > 0) {
-                    // TODO: support rich text fragments
-                }*/
+                    /*if (rt.numFormattingRuns() > 0) {
+                        // TODO: support rich text fragments
+                    }*/
 
-                width = getCellWidth(defaultCharWidth, colspan, style, width, str);
+                    width = getCellWidth(defaultCharWidth, colspan, style, width, str);
+                }
             }
         } else {
             String sval = null;