From c2d2ec0eaf9b994820810a9b561ab7a5b49557c5 Mon Sep 17 00:00:00 2001
From: PJ Fanning
Date: Thu, 9 Feb 2023 15:22:21 +0000
Subject: [PATCH] DataFormatter - typo in javadoc and possible NPE
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1907543 13f79535-47bb-0310-9956-ffa450edef68
---
.../java/org/apache/poi/ss/usermodel/DataFormatter.java | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
index 54b1bfe8b1..fe14527066 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/DataFormatter.java
@@ -99,7 +99,7 @@ import org.apache.poi.util.StringUtil;
* The trailing underscore and space ("_ ") in the format adds a space to the end and Excel formats this cell as {@code "12.34 "},
* but {@code DataFormatter} trims the formatted value and returns {@code "12.34"}.
*
- * You can enable spaces by passing the {@code emulateCSV=true} flag in the {@code DateFormatter} cosntructor.
+ * You can enable spaces by passing the {@code emulateCSV=true} flag in the {@code DateFormatter} constructor.
* If set to true, then the output tries to conform to what you get when you take an xls or xlsx in Excel and Save As CSV file:
*
* - returned values are not trimmed
@@ -496,7 +496,11 @@ public class DataFormatter {
return generalNumberFormat;
}
- if(DateUtil.isADateFormat(formatIndex,formatStr) &&
+ if (formatStr == null) {
+ return null;
+ }
+
+ if(DateUtil.isADateFormat(formatIndex, formatStr) &&
DateUtil.isValidExcelDate(cellValue)) {
return createDateFormat(formatStr, cellValue);
}