Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 483342

Summary: CTabFolder throws exception which also can cause leaks and disposed object reference
Product: [Eclipse Project] Platform Reporter: Elena Laskavaia <elaskavaia.cdt>
Component: SWTAssignee: Platform-SWT-Inbox <platform-swt-inbox>
Status: RESOLVED WORKSFORME QA Contact:
Severity: normal    
Priority: P3 CC: akurtakov, ericwill, xixiyan
Version: 4.6Keywords: triaged
Target Milestone: ---   
Hardware: PC   
OS: Linux   
Whiteboard:
Attachments:
Description Flags
Vertical resize
none
Horizontal resize none

Description Elena Laskavaia CLA 2015-11-30 22:23:54 EST
There is an exception in CTabFolder when I try to resize a view
containing CTabFolder. I passed bounds to image constructor with values
Rectangle {0, -1, 10, -2} which is invalid (where 10/-2 is width/hight)



java.lang.IllegalArgumentException: Argument not valid
	at org.eclipse.swt.SWT.error(SWT.java:4484)
	at org.eclipse.swt.SWT.error(SWT.java:4418)
	at org.eclipse.swt.SWT.error(SWT.java:4389)
	at org.eclipse.swt.graphics.Image.init(Image.java:1476)
	at org.eclipse.swt.graphics.Image.<init>(Image.java:545)
	at org.eclipse.swt.custom.CTabFolder.updateBkImages(CTabFolder.java:3847)
	at org.eclipse.swt.custom.CTabFolder.setButtonBounds(CTabFolder.java:2582)
	at org.eclipse.swt.custom.CTabFolder.updateItems(CTabFolder.java:3757)
	at org.eclipse.swt.custom.CTabFolder.updateItems(CTabFolder.java:3688)
	at org.eclipse.swt.custom.CTabFolder.onResize(CTabFolder.java:2081)
	at org.eclipse.swt.custom.CTabFolder$1.handleEvent(CTabFolder.java:337)
	at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4482)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1329)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1353)
	at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1334)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:1067)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1449)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:900)
	at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:693)
	at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:197)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1666)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1452)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:900)
	at org.eclipse.swt.layout.FillLayout.layout(FillLayout.java:204)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1666)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1452)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:900)
	at org.eclipse.swt.layout.FillLayout.layout(FillLayout.java:219)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1666)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1452)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:900)
	at org.eclipse.swt.layout.FillLayout.layout(FillLayout.java:204)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1666)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1452)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:867)
	at org.eclipse.swt.custom.CTabFolderLayout.layout(CTabFolderLayout.java:116)
	at org.eclipse.swt.widgets.Composite.updateLayout(Composite.java:1666)
	at org.eclipse.swt.widgets.Composite.setBounds(Composite.java:1452)
	at org.eclipse.swt.widgets.Control.setBounds(Control.java:867)
	at org.eclipse.e4.ui.workbench.renderers.swt.SashLayout.setRectangle(SashLayout.java:319)

--

Also because disposal of gc and images not done in finally blocks up
the chain it causing resource leaks
at org.eclipse.swt.custom.CTabFolder.updateItems(CTabFolder.java:3757)
- here we will leak gc because setButtonBounds retrows this exception

--

Disposed object will be held here
CTabFolder.java:3847
						if (controlBkImages[i] != null) controlBkImages[i].dispose();
						controlBkImages[i] = new Image(control.getDisplay(), bounds);
- Since new Image... throws exception above controlBkImages[i] now contains disposed image, not sure if usage of this image will cause problems later...
Comment 1 Elena Laskavaia CLA 2015-11-30 22:45:58 EST
Note: I don't have snippet but in my example tabs are at the bottom,
there are 11 tab and I resize the view vertically to shrink (or horizontally). Weird stuff is shown.
Comment 2 Elena Laskavaia CLA 2015-11-30 22:47:04 EST
Created attachment 258375 [details]
Vertical resize
Comment 3 Elena Laskavaia CLA 2015-11-30 22:48:00 EST
Created attachment 258376 [details]
Horizontal resize
Comment 4 Alexander Kurtakov CLA 2015-12-02 14:52:48 EST
Coming with a snippet for debugging/reproducing purposes would help fixing/finding the issue. One thing I don't get is why do you create such image/rectangle combo or you mean CTabFolder comes with such values internally.
Regarding leaks, have you investigated yourself about reducing them?
Comment 5 Elena Laskavaia CLA 2015-12-02 15:18:57 EST
Leaks are from that background image in CTabFolder. I think because exception is thrown so it does not get to clean up properly.

This rectangle from CTabFolder code, if you look at code from stacktace
it creates rect with negative bounds and passes it to new Image.
I suspect this is caused by some bug in CTabFolder layout but CTabFolder should
at least do some sanity check when it comes up with such values for the image.
Comment 6 Xi Yan CLA 2018-12-19 14:20:11 EST
Is this still reproducible?
Comment 7 Eric Williams CLA 2019-10-03 15:52:53 EDT
(In reply to Xi Yan from comment #6)
> Is this still reproducible?

No response from the OP so I am closing this one. Please feel free to re-open it if the issue still reproduces with latest SWT.