Bug 540789 - Control.setForeground(Color) no longer throws an exception if color is disposed
Summary: Control.setForeground(Color) no longer throws an exception if color is disposed
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.9   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.10 M3   Edit
Assignee: Simeon Andreev CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
Depends on:
Blocks:
 
Reported: 2018-11-05 06:04 EST by Simeon Andreev CLA
Modified: 2018-11-20 15:36 EST (History)
2 users (show)

See Also:


Attachments
Snippet to reproduce the problem with. Run and observe no exception. (837 bytes, text/x-java)
2018-11-05 06:04 EST, Simeon Andreev CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Simeon Andreev CLA 2018-11-05 06:04:58 EST
Created attachment 276469 [details]
Snippet to reproduce the problem with. Run and observe no exception.

Running the attached snippet "Bug_test_disposed_color.java" on 4.9 platform results in:

Exception in thread "main" java.lang.IllegalArgumentException: Argument not valid

Running the snippet on 4.10 results in no exception.

The change is coming from GTK2 support removal in 4.10, commit:

https://git.eclipse.org/c/platform/eclipse.platform.swt.git/diff/bundles/org.eclipse.swt/Eclipse%20SWT/gtk/org/eclipse/swt/widgets/Control.java?id=653f05d5c8bf3e06e39139572ab8e000d66bc4bc

 public void setForeground (Color color) {
 	checkWidget();
 	if (((state & FOREGROUND) == 0) && color == null) return;
-	GdkColor gdkColor = null;
-	if (color != null) {
-		if (color.isDisposed ()) error(SWT.ERROR_INVALID_ARGUMENT);
-		gdkColor = color.handle;
-	}

No exception means programming errors which dispose a color would go unnoticed and there would be no effect in setting the disposed color; Control.setForegroundGdkRGBA will use the default foreground color in case the color is disposed.
Comment 1 Andrey Loskutov CLA 2018-11-05 10:15:53 EST
Simeon, can you provide a patch and test? Please for the test, check not only setForeground() but also setBackground().

Not sure what it was in 4.9, but on 4.10 it is also broken in the sense that instead of IllegalArgumentException as declared in javadoc it throws "org.eclipse.swt.SWTException: Graphic is disposed".
Comment 2 Eclipse Genie CLA 2018-11-05 12:38:55 EST
New Gerrit change created: https://git.eclipse.org/r/131939
Comment 4 Eric Williams CLA 2018-11-05 13:55:26 EST
(In reply to Eclipse Genie from comment #3)
> Gerrit change https://git.eclipse.org/r/131939 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/
> ?id=4d89403a72c43b535e3cee44a63a52ac58799144

In master now.
Comment 5 Eric Williams CLA 2018-11-20 15:36:59 EST
Verified in I20181120-0600.