jxls
jxls copied to clipboard
cannot read double value if cell is empty
I am using jxls 2.14.0
and jxls-reader 2.1.0
, commons-beanutils 1.9.4
, the java code is:
XLSReader mainReader = ReaderBuilder.buildFromXML(xmlConfig);
mainReader.getConvertUtilsBeanProvider().getConvertUtilsBean().register(new JxlsDateConverter(),
java.util.Date.class);
ReaderConfig.getInstance().setUseDefaultValuesForPrimitiveTypes(true);
XLSReadStatus readStatus = mainReader.read( dataInputStream, beanMap);
there is double value type in excel template and value left empty, and the java type is Double
.
The tester told me that our system throws an exception saying that cannot read this cell value when it is empty in the test server.
I can repeat this problem in my local pc, I tried to debug and found that in AbstractConverter
of commons-beanutils
:
protected <T> T handleMissing(final Class<T> type) {
if (useDefault || type.equals(String.class)) {
....
// value is now either null or of the desired target type
return type.cast(value);
}
final ConversionException cex = new ConversionException("No value specified for '" +
toString(type) + "'");
the useDefault
is false
, so it skip this if
and throws ConversionException
.
I can repeat this problem in my pc many times.
However, when I debug, the tester told me that he cannot repeat again without any code changed. Meanwhile, after I added break point on super
of
public DoubleConverter(final Object defaultValue) {
super(true, defaultValue);
}
and click step into
in debug until read process finished, I also cannot repeat this problem any more in my local pc, very strange. Then I remove break point of DoubleConverter
, I still cannot repeat this problem.
it seems that this problem disappear after I click step into
from DoubleConverter
.