Bug 44246

Summary: Auto size of columns while generating xls throws null pointer exception
Product: POI Reporter: John J. Aylward <johnjaylward>
Component: HSSFAssignee: POI Developers List <dev>
Status: RESOLVED FIXED    
Severity: major    
Priority: P2    
Version: 3.0-FINAL   
Target Milestone: ---   
Hardware: Other   
OS: Linux   

Description John J. Aylward 2008-01-15 10:45:44 UTC
java.lang.NullPointerException

    at java.lang.String.<init>(String.java:83) at

org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1468)

    at
Comment 1 Yegor Kozlov 2008-01-15 23:03:22 UTC
Could you upload the problem xls file? 

Yegor
Comment 2 John J. Aylward 2008-01-16 06:12:03 UTC
no, it contains client financial data. I'm not sure I could anonymize it without
changing the result. I think the problem may be that some of the data that is
pulled back is null valued, and I'm setting that to the xls cell, but I'm unsure.
Comment 3 Nick Burch 2008-01-16 06:50:35 UTC
Unfortunately, without the excel file, it's going to be pretty difficult for us
to fix, and certainly almost impossible to write tests so we can be sure we
don't regress the issue at a later date

If you load the file up in poi, save it, and load it up again, do you still get
the same null pointer? If so, you could just try running through changing all
the strings to one value, and all the numbers to another, and checking that
still gives the problem
Comment 4 Yegor Kozlov 2008-01-16 07:12:07 UTC
1. Please try the latest POI-3.0.2-BETA2. 
2. If the error persists, provide the full stack trace. In the latest version of
POI HSSFSheet.autoSizeColumn starts at line 1632 so I can't even see where it is
happening.
3. Is anything special about your xls? Is it Excel-generated or imported from
OpenOffice? Give us any possible hints. 

Regards,
Yegor  

Comment 5 John J. Aylward 2008-01-16 08:16:44 UTC
1. I can try this, but not sure how soon to get you results. I'll do it asap
2. I'm using POI-3.0.1FINAL, you should have a tag in the source control you can
use to match against the file.
3. The XLS file is 100% generated using POI, and is not saved to disk until all
processing is finished.
Comment 6 John J. Aylward 2008-01-16 08:29:44 UTC
ok, ran with beta 2, same result different line number, although it still
doesn't match the one you said the function starts at:

java.lang.NullPointerException
        at java.lang.String.<init>(String.java:83)
        at
org.apache.poi.hssf.usermodel.HSSFSheet.autoSizeColumn(HSSFSheet.java:1625)
        at
com.cicat.bedrock.billing.actions.CustomerInvoiceRegister.createSubSheet(CustomerInvoiceRegister.java:301)
        at
com.cicat.bedrock.billing.actions.CustomerInvoiceRegister.doCreateDataFile(CustomerInvoiceRegister.java:535)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:79)
        at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:618)
        at
com.opensymphony.xwork.DefaultActionInvocation.invokeAction(DefaultActionInvocation.java:358)
        at
com.opensymphony.xwork.DefaultActionInvocation.invokeActionOnly(DefaultActionInvocation.java:218)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:192)
        at
com.opensymphony.xwork.interceptor.DefaultWorkflowInterceptor.doIntercept(DefaultWorkflowInterceptor.java:175)
        at
com.opensymphony.xwork.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.validator.ValidationInterceptor.doIntercept(ValidationInterceptor.java:115)
        at
com.opensymphony.xwork.interceptor.MethodFilterInterceptor.intercept(MethodFilterInterceptor.java:86)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.cicat.bedrock.core.actions.interceptors.HibernateSession.executeInTransaction(HibernateSession.java:96)
        at
com.cicat.bedrock.core.actions.interceptors.HibernateSession.intercept(HibernateSession.java:151)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.webwork.interceptor.FileUploadInterceptor.intercept(FileUploadInterceptor.java:174)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.webwork.interceptor.debugging.DebuggingInterceptor.intercept(DebuggingInterceptor.java:169)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.I18nInterceptor.intercept(I18nInterceptor.java:151)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.AroundInterceptor.intercept(AroundInterceptor.java:31)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.interceptor.ExceptionMappingInterceptor.intercept(ExceptionMappingInterceptor.java:186)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.cicat.bedrock.core.actions.interceptors.CheckLoggedIn.intercept(CheckLoggedIn.java:55)
        at
com.opensymphony.xwork.DefaultActionInvocation.invoke(DefaultActionInvocation.java:190)
        at
com.opensymphony.xwork.DefaultActionProxy.execute(DefaultActionProxy.java:116)
        at
com.opensymphony.webwork.dispatcher.DispatcherUtils.serviceAction(DispatcherUtils.java:273)
        at
com.opensymphony.webwork.dispatcher.ServletDispatcher.service(ServletDispatcher.java:111)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:874)
        at
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
        at
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
        at
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
        at
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:689)
        at java.lang.Thread.run(Thread.java:810)
Comment 7 John J. Aylward 2008-01-16 08:40:13 UTC
(In reply to comment #2)
> I think the problem may be that some of the data that is
> pulled back is null valued, and I'm setting that to the xls cell, but I'm unsure.

re-looking at my code, I do not set a value for a cell in which my returned DB
data is null or an empty string. So it's possible that some cell data in the
middle of a column is in an unset state. i.e.

Row# | Column 1
1    | test val
2    |
3    | test val3

where row 2 column 1 has not called cell.setCellValue() before calling
sheet.autoSizeColumn()
Comment 8 Yegor Kozlov 2008-01-19 06:29:58 UTC
I added a check to prevent NPE. 
Try the latest build. You can download it from 
http://encore.torchbox.com/poi-svn-build/

Regards,
Yegor