NullPointerException when exporting nattable [message #1052812] |
Tue, 30 April 2013 11:03  |
Eclipse User |
|
|
|
Hello,
I have recently upgraded Nattable to 0.9.0. I had to make very few changes to my application code for successfully migrating to the newer version. And the new version looks quite crisp.
One feature I like very much is the "Export to Excel" feature, which was broken in the older version.
I have added the 'Export' icon for this feature to one of the ViewParts in my application. Now I found one issue with the current implementation.
Here's how to reproduce it:
1. Click on the "Export" Icon
2. Internally I have associated with the org.eclipse.nebula.widgets.nattable.export.command.ExportCommand(IConfigRegistry configRegistry, Shell shell).
3. This command calls the ExportCommandHandler, which in turn calls the NatExporter.exportSingleLayer() API.
4. So on the UI I get a File Dialog to Save the xls.
5. If I choose to Save the file then everything works well.
6. However on the File Dialog if I select 'Cancel' and then again try to Export the ViewPart by clicking on the 'Export' icon I get following exception:
java.lang.NullPointerException
at org.eclipse.nebula.widgets.nattable.export.FileOutputStreamProvider.getOutputStream(FileOutputStreamProvider.java:40)
at org.eclipse.nebula.widgets.nattable.export.excel.ExcelExporter.getOutputStream(ExcelExporter.java:46)
at org.eclipse.nebula.widgets.nattable.export.NatExporter.exportSingleLayer(NatExporter.java:44)
at org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler.doCommand(ExportCommandHandler.java:33)
at org.eclipse.nebula.widgets.nattable.export.command.ExportCommandHandler.doCommand(ExportCommandHandler.java:1)
at org.eclipse.nebula.widgets.nattable.command.AbstractLayerCommandHandler.doCommand(AbstractLayerCommandHandler.java:19)
at org.eclipse.nebula.widgets.nattable.layer.AbstractLayer.doCommand(AbstractLayer.java:152)
at org.eclipse.nebula.widgets.nattable.layer.CompositeLayer.doCommand(CompositeLayer.java:137)
at org.eclipse.nebula.widgets.nattable.grid.layer.GridLayer.doCommand(GridLayer.java:169)
at org.eclipse.nebula.widgets.nattable.NatTable.doCommand(NatTable.java:507)
The fix for this is pretty simple actually. To save the xls file there is a call to FileOutputStreamProvider.getOutputStream(Shell shell) method where the fileName is passed as an argument to the constructor.
fileName = dialog.open();
if (fileName == null) {
return null;
}
Now if I choose to CANCEL the file dialog, fileName gets set to null, which is an instance variable. So next time when this method is called following code throws NullPointerException.
int lastIndexOfFileSeparator = fileName.lastIndexOf(File.separator);
The fix is, take the return value from dialog.open() to a local variable and compare that, instead of setting it to fileName
String dialogStatus = dialog.open();
if(dialogStatus == null) {
return null;
}
Can we have this fix added in a patch please?
This export feature is one of the crucial functionality we are adding to our app.
You help is much appreciated.
Thanks.
|
|
|
|
Powered by
FUDForum. Page generated in 0.04546 seconds