Bug 44456 - I need to view a .xsl file with an empty row into the table
Summary: I need to view a .xsl file with an empty row into the table
Status: RESOLVED FIXED
Alias: None
Product: POI
Classification: Unclassified
Component: HSSF (show other bugs)
Version: unspecified
Hardware: Other other
: P2 normal (vote)
Target Milestone: ---
Assignee: POI Developers List
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2008-02-20 10:03 UTC by Giuseppe Piccoli
Modified: 2008-02-22 06:11 UTC (History)
0 users



Attachments
svn diff of one changed file (940 bytes, patch)
2008-02-20 11:56 UTC, Josh Micich
Details | Diff
sreenshot of the new problem. (40.14 KB, image/jpeg)
2008-02-21 00:36 UTC, Giuseppe Piccoli
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Giuseppe Piccoli 2008-02-20 10:03:12 UTC
I need to view an .xsl file using apache poi libraries. 
My .xsl files contain an empty row into the table 

e.g. (extract from the table)


a	a	a
a	a	a
a	a	a
		     <---- Empty row
a	a	a
a	a	a
a	a	a


But when I try to excecute the main method in the SViewerPanel.java with 
argumet the .xsl file, the application throw 
the following Exception :


Exception in thread "main" java.lang.NullPointerException
	at 
org.apache.poi.hssf.contrib.view.SVRowHeader$RowHeaderRenderer.getListCellRender
erComponent(SVRowHeader.java:77)
	at javax.swing.plaf.basic.BasicListUI.updateLayoutState
(BasicListUI.java:1148)
	at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState
(BasicListUI.java:1098)
	at javax.swing.plaf.basic.BasicListUI.getPreferredSize
(BasicListUI.java:281)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
	at javax.swing.JList.getPreferredScrollableViewportSize(JList.java:1913)
	at javax.swing.ViewportLayout.preferredLayoutSize
(ViewportLayout.java:72)
	at java.awt.Container.preferredSize(Container.java:1178)
	at java.awt.Container.getPreferredSize(Container.java:1162)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
	at javax.swing.ScrollPaneLayout.layoutContainer
(ScrollPaneLayout.java:717)
	at java.awt.Container.layout(Container.java:1020)
	at java.awt.Container.doLayout(Container.java:1010)
	at java.awt.Container.validateTree(Container.java:1092)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validate(Container.java:1067)
	at java.awt.Window.show(Window.java:461)
	at java.awt.Component.show(Component.java:1133)
	at java.awt.Component.setVisible(Component.java:1088)
	at org.apache.poi.hssf.contrib.view.SViewerPanel.main
(SViewerPanel.java:287)

May you help me?
Comment 1 Josh Micich 2008-02-20 11:54:20 UTC
HSSFSheet.getRow(int) may return null if the row is missing.  This call 
appears to be on line 76 in the latest version.  I can't find a good 
explanation for why your stacktrace says line 77.  If the NPE is really coming 
from 'd.height' (on line 77), then please ignore this posting.

This is the current code:
      Dimension d = getPreferredSize();
      int rowHeight = (int)sheet.getRow(index).getHeightInPoints();
      d.height = rowHeight+extraHeight;

I would propose this fix:
      Dimension d = getPreferredSize();
      HSSFRow row = sheet.getRow(index);
      int rowHeight;
      if(row == null) {
    	  rowHeight = (int)sheet.getDefaultRowHeightInPoints();
      } else {
    	  rowHeight = (int)row.getHeightInPoints();
      }
      d.height = rowHeight+extraHeight;
Comment 2 Josh Micich 2008-02-20 11:56:15 UTC
Created attachment 21571 [details]
svn diff of one changed file
Comment 3 Giuseppe Piccoli 2008-02-20 23:23:43 UTC
(In reply to comment #1)
> HSSFSheet.getRow(int) may return null if the row is missing.  This call 
> appears to be on line 76 in the latest version.  I can't find a good 
> explanation for why your stacktrace says line 77.  If the NPE is really 
coming 
> from 'd.height' (on line 77), then please ignore this posting.
> This is the current code:
>       Dimension d = getPreferredSize();
>       int rowHeight = (int)sheet.getRow(index).getHeightInPoints();
>       d.height = rowHeight+extraHeight;
> I would propose this fix:
>       Dimension d = getPreferredSize();
>       HSSFRow row = sheet.getRow(index);
>       int rowHeight;
>       if(row == null) {
>     	  rowHeight = (int)sheet.getDefaultRowHeightInPoints();
>       } else {
>     	  rowHeight = (int)row.getHeightInPoints();
>       }
>       d.height = rowHeight+extraHeight;

Yes the correct row is 76, in my cut & paste I have attached the wrong 
StackTrace. Now I rewrite the correct StackTrace:


Exception in thread "main" java.lang.NullPointerException
	at 
org.apache.poi.hssf.contrib.view.SVRowHeader$RowHeaderRenderer.getListCellRender
erComponent(SVRowHeader.java:76)
	at javax.swing.plaf.basic.BasicListUI.updateLayoutState
(BasicListUI.java:1148)
	at javax.swing.plaf.basic.BasicListUI.maybeUpdateLayoutState
(BasicListUI.java:1098)
	at javax.swing.plaf.basic.BasicListUI.getPreferredSize
(BasicListUI.java:281)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1275)
	at javax.swing.JList.getPreferredScrollableViewportSize(JList.java:1913)
	at javax.swing.ViewportLayout.preferredLayoutSize
(ViewportLayout.java:72)
	at java.awt.Container.preferredSize(Container.java:1178)
	at java.awt.Container.getPreferredSize(Container.java:1162)
	at javax.swing.JComponent.getPreferredSize(JComponent.java:1277)
	at javax.swing.ScrollPaneLayout.layoutContainer
(ScrollPaneLayout.java:717)
	at java.awt.Container.layout(Container.java:1020)
	at java.awt.Container.doLayout(Container.java:1010)
	at java.awt.Container.validateTree(Container.java:1092)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validateTree(Container.java:1099)
	at java.awt.Container.validate(Container.java:1067)
	at java.awt.Window.show(Window.java:461)
	at java.awt.Component.show(Component.java:1133)
	at java.awt.Component.setVisible(Component.java:1088)
	at org.apache.poi.hssf.contrib.view.SViewerPanel.main
(SViewerPanel.java:287)
Comment 4 Giuseppe Piccoli 2008-02-21 00:36:41 UTC
Created attachment 21572 [details]
sreenshot of the new problem.

I have made changes described in your attachment (id=21571). Now the table is
correctly displayed, but there's still a little bug: the last row doesn't have
a corresponding row number in the left enumeration column. I attach you a
screenshot of the problem. 
I have some questions, due to I'm a beginnes in submit an issue into a Bugzilla
system: 
1) which version of libraries will have changes, when the issue will be
resolved?
2) what are the formal step that I do to completed this issue?

Thank you in advance.
Comment 5 Giuseppe Piccoli 2008-02-21 00:41:06 UTC
3) In which version of the library the fix will be delivered? 
Can I include the fixed source code into my distribution, in respect with 
Apache License?
Comment 6 Nick Burch 2008-02-21 02:51:33 UTC
Thanks for the patch Josh, looks just the job. Applied in svn.

I've also fixed the missing row numbers problem, which was caused by calling
getPhysicalNumberOfRows when we meant to call getLastRowNumber. Now works fine
with the version in svn.

Giuseppe - fixes are ASL licensed, so you're welcome to use them under the same
terms as the rest of poi. They're in svn now, will be in tonight's nightly
build, and will be included in the next release
Comment 7 Giuseppe Piccoli 2008-02-22 06:08:15 UTC
I've tried to perform changes from getPhysicalNumberOfRows to getLastRowNum() 
(getLastRowNumber) in SViewerPanel.java and SVRowHeader.java classes, but the 
bug is still present. I have also noted that the table row was eliminated into 
the .xls file.
Comment 8 Nick Burch 2008-02-22 06:11:11 UTC
Please try with a svn checkout from trunk. 

If the problem remains, please attach a problem excel file so we can test
against that - all my sample files now work just fine.