You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@poi.apache.org by "sanjeev.x.verma" <sa...@gmail.com> on 2010/12/08 01:13:46 UTC
NullPointerException in
org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun
Gurus:
While executing the autoSizeColumn method of the XSSFSheet in my code (using
POI-3.7), I am getting a NPE. The stack trace is as below:
java.lang.NullPointerException
at
org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun(XSSFRichTextString.java:334)
at
org.apache.poi.xssf.usermodel.helpers.ColumnHelper.getColumnWidth(ColumnHelper.java:370)
at
org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:337)
at
org.apache.poi.xssf.usermodel.XSSFSheet.autoSizeColumn(XSSFSheet.java:320)
at
com.xxx.yyyy.precalc.server.SpreadSheetMaker.formatDataSheet(SpreadSheetMaker.java:329)
at
com.xxx.yyyy.precalc.server.SpreadSheetMaker.createSpreadsheetForUpdate(SpreadSheetMaker.java:274)
at
com.xxx.yyyy.precalc.server.SpreadSheetMaker.getSpreadSheet(SpreadSheetMaker.java:75)
at
com.xxx.yyyy.InsertUpdateSpreadsheetServlet.doGet(InsertUpdateSpreadsheetServlet.java:35)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
at
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:525)
at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:662)
When I looked at the source code of XSSFRichTextString, i see this:
/**
* Returns the number of characters this format run covers.
*
* @param index the index of the formatting run
* @return the number of characters this format run covers
*/
public int getLengthOfFormattingRun(int index) {
if(st.sizeOfRArray() == 0) return length();
for(int i = 0; i < st.sizeOfRArray(); i++){
CTRElt r = st.getRArray(i);
if(i == index) return r.getT().length(); //<<<This is
where the NPE is thrown
}
return -1;
}
Looking at this code, I am assuming the the object "r"obtained in the line
above the offending code is null, thereby the NPE on the line below. Can we
add a null check on the if condition, like this:
if(r != null && i == index) return r.getT().length();
//<<<Add a null check for "r"
will this solution work? Not having looked at the deeper levels, i cannot be
certain, so will appreciate inputs.
Or, am I doing something wrong that needs to be fixed? If so, please let me
know.
Thanks for looking!
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/NullPointerException-in-org-apache-poi-xssf-usermodel-XSSFRichTextString-getLengthOfFormattingRun-tp3296746p3296746.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: NullPointerException in
org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun
Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 7 Dec 2010, sanjeev.x.verma wrote:
> CTRElt r = st.getRArray(i);
> if(r != null
> && r.getT() != null
> && i == index) return r.getT().length(); //<<<Null
> check here - "r.getT()" was returning null.
I'm not sure why r.getT() would return null, so we'll need to see the file
to be sure
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: NullPointerException in
org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun
Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 7 Dec 2010, sanjeev.x.verma wrote:
> Since the exception was being thrown while generating a excel file from
> a datasource, I am afraid i do not have a file that you could use as a
> test case.
Could you generate the file without the autosize step, then share that?
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: NullPointerException in
org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun
Posted by "sanjeev.x.verma" <sa...@gmail.com>.
Hey Nick, thanks for the quick reply. After a few hit and trials, I am able
to get rid of the NPE by making the following change to
"XSSFRichTextString.java".
/**
* Returns the number of characters this format run covers.
*
* @param index the index of the formatting run
* @return the number of characters this format run covers
*/
public int getLengthOfFormattingRun(int index) {
if(st.sizeOfRArray() == 0) return length();
for(int i = 0; i < st.sizeOfRArray(); i++){
CTRElt r = st.getRArray(i);
if(r != null
&& r.getT() != null
&& i == index) return r.getT().length(); //<<<Null
check here - "r.getT()" was returning null.
}
return -1;
}
Since the exception was being thrown while generating a excel file from a
datasource, I am afraid i do not have a file that you could use as a test
case. I will try and run autoSizeColumn() on the generated file with the
original code and see if that throws an exception. Will let you know.
Thanks again!
--
View this message in context: http://apache-poi.1045710.n5.nabble.com/NullPointerException-in-org-apache-poi-xssf-usermodel-XSSFRichTextString-getLengthOfFormattingRun-tp3296746p3296789.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org
Re: NullPointerException in
org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun
Posted by Nick Burch <ni...@alfresco.com>.
On Tue, 7 Dec 2010, sanjeev.x.verma wrote:
> While executing the autoSizeColumn method of the XSSFSheet in my code (using
> POI-3.7), I am getting a NPE. The stack trace is as below:
>
> java.lang.NullPointerException
> at
> org.apache.poi.xssf.usermodel.XSSFRichTextString.getLengthOfFormattingRun(XSSFRichTextString.java:334)
Can you create a new bug in bugzilla, and upload a file that shows the
problem? We can then use that to test the fix, and going forward include a
unit test to ensure we don't break it again in the future!
Thanks
Nick
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@poi.apache.org
For additional commands, e-mail: user-help@poi.apache.org