Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » NatTable » Division by Zero bug in AbstractTextPainter.modifyTextToDisplay(AbstractTextPainter.java:325)(This method is buggy - please fix!)
icon13.gif  Division by Zero bug in AbstractTextPainter.modifyTextToDisplay(AbstractTextPainter.java:325) [message #926316] Fri, 28 September 2012 14:26 Go to next message
Olaf Gottschalk is currently offline Olaf Gottschalk
Messages: 2
Registered: September 2012
Junior Member
Hello folks,

I just get started with Nattable and already enjoy finding critical bugs in Nattable that nobody else seems to have found so far... *sigh*

In AbstractTextPainter a method called modifyTextToDisplay tries to figure out when a column is not wide enough to accommodate the given text. Line 325 says:

numExtraChars = 1 + (newTextExtent - availableLength) / avgWidthPerChar;


but avgWidthPerChar is not checked against 0 => thus it is quite easy to get an ArithmeticException exception.

Try to display the text in String s in a cell: (has to be long enough and contain multiple lines so just for here I present this horrible code... Smile)
String s = "Bundle state:\n";
for( int i = 0; i < 20; i++ ) {
   s = s +
      "\ncom.test.test.base.xtext.ded v2.2.0.RC8-SNAPSHOTv20120814-133856-13284 [4: active]";
}


You instantly get this exception:
java.lang.ArithmeticException: / by zero
	at net.sourceforge.nattable.painter.cell.AbstractTextPainter.modifyTextToDisplay(AbstractTextPainter.java:325)
	at net.sourceforge.nattable.painter.cell.AbstractTextPainter.getTextToDisplay(AbstractTextPainter.java:250)
	at net.sourceforge.nattable.painter.cell.TextPainter.paintCell(TextPainter.java:99)
	at net.sourceforge.nattable.painter.cell.CellPainterWrapper.paintCell(CellPainterWrapper.java:51)
	at net.sourceforge.nattable.painter.cell.decorator.PaddingDecorator.paintCell(PaddingDecorator.java:55)
	at net.sourceforge.nattable.painter.layer.CellLayerPainter.paintCell(CellLayerPainter.java:60)
	at net.sourceforge.nattable.selection.SelectionLayerPainter.paintCell(SelectionLayerPainter.java:143)
	at net.sourceforge.nattable.painter.layer.CellLayerPainter.paintLayer(CellLayerPainter.java:32)
	at net.sourceforge.nattable.painter.layer.GridLineCellLayerPainter.paintLayer(GridLineCellLayerPainter.java:31)
	at net.sourceforge.nattable.selection.SelectionLayerPainter.paintLayer(SelectionLayerPainter.java:34)
	at net.sourceforge.nattable.layer.CompositeLayer$CompositeLayerPainter.paintLayer(CompositeLayer.java:898)
	at net.sourceforge.nattable.painter.layer.NatLayerPainter.paintLayer(NatLayerPainter.java:26)
	at net.sourceforge.nattable.NatTable.paintNatTable(NatTable.java:313)
	at net.sourceforge.nattable.NatTable.paintControl(NatTable.java:309)
	at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:229)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1077)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1062)
	at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1463)
	at org.eclipse.swt.widgets.Control.windowProc(Control.java:4585)
	at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:341)
	at org.eclipse.swt.widgets.Display.windowProc(Display.java:4985)
	at org.eclipse.swt.internal.win32.OS.UpdateWindow(Native Method)
	at org.eclipse.swt.widgets.Decorations.setVisible(Decorations.java:1418)
	at org.eclipse.swt.widgets.Shell.setVisible(Shell.java:1888)
	at org.eclipse.swt.widgets.Shell.open(Shell.java:1229)
	at com.test.test.logviewer.ViewerMain.main(ViewerMain.java:279)
Error while painting table: / by zero


Could somebody please confirm this and try to fix it, please?
Thanks!
Re: Division by Zero bug in AbstractTextPainter.modifyTextToDisplay(AbstractTextPainter.java:325) [message #926337 is a reply to message #926316] Fri, 28 September 2012 14:56 Go to previous messageGo to next message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1334
Registered: July 2012
Senior Member
Hi,

so of which version are we speaking? This bug was already reported if you have a look at bugzilla. And it is already fixed in 0.9.0

https://bugs.eclipse.org/bugs/show_bug.cgi?id=383877
https://bugs.eclipse.org/bugs/show_bug.cgi?id=379919

Thanks for reporting this bug, but I can't confirm this anymore, as it was fixed already. Smile

Greez,
Dirk


Re: Division by Zero bug in AbstractTextPainter.modifyTextToDisplay(AbstractTextPainter.java:325) [message #928994 is a reply to message #926337] Mon, 01 October 2012 06:00 Go to previous messageGo to next message
Olaf Gottschalk is currently offline Olaf Gottschalk
Messages: 2
Registered: September 2012
Junior Member
Oh, sorry. I installed the latest version that I could download - so I presumed that it could not be fixed yet. Sad
In my manifest I see net.sourceforge.nattable.core (2.3.2) - where do I find a version number like 0.9.0??
Re: Division by Zero bug in AbstractTextPainter.modifyTextToDisplay(AbstractTextPainter.java:325) [message #929035 is a reply to message #928994] Mon, 01 October 2012 06:49 Go to previous message
Dirk Fauth is currently offline Dirk Fauth
Messages: 1334
Registered: July 2012
Senior Member
Hi,

we moved to Nebula some months ago. But in fact released the Nebula NatTable 0.9.0 last week. You can download it here

http://eclipse.org/nattable/download.php

You will also find documentation, news and more information about the NatTable at http://eclipse.org/nattable/

If you find other bugs, feel free to report them in Bugzilla, as we want to improve the quality of code and documentation continually. And we're getting better and better. Wink

As the Sourceforge trunk is closed, you will have to migrate the package names and some little API changes appeared. But they shouldn't affect you if you haven't extended some features already.

Greez,
Dirk
Previous Topic:Text editor control decoration
Next Topic:Row Filter
Goto Forum:
  


Current Time: Mon Oct 20 21:27:09 GMT 2014

Powered by FUDForum. Page generated in 0.02250 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software