Bug 513180 - GridLayout should give additional information if wrong layout data is used
Summary: GridLayout should give additional information if wrong layout data is used
Status: RESOLVED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.6   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: helpwanted, triaged
Depends on:
Blocks:
 
Reported: 2017-03-06 11:45 EST by Lars Vogel CLA
Modified: 2020-06-12 06:24 EDT (History)
7 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Lars Vogel CLA 2017-03-06 11:45:26 EST
I suggest to use a IAE instead of a ClassCastException in GridLayout if one of its children has wrong layout data set. Also we should print out the control and its current layout data to make it easier to find the control.
Comment 1 Eclipse Genie CLA 2017-03-06 11:46:02 EST
New Gerrit change created: https://git.eclipse.org/r/92393
Comment 3 Alexander Kurtakov CLA 2017-03-20 04:37:54 EDT
Pushed. Test case that verifies this exception properly occurs has to be added.
Comment 4 Eclipse Genie CLA 2017-03-20 04:55:35 EDT
New Gerrit change created: https://git.eclipse.org/r/93399
Comment 5 Markus Keller CLA 2017-03-20 13:11:10 EDT
Throwing an IAE in org.eclipse.swt.layout.GridLayout#layout(Composite, boolean) is misleading.

Javadoc of IllegalArgumentException:
 * Thrown to indicate that a method has been passed an illegal or
 * inappropriate argument.

The arguments passed to the layout method are OK. Only the internal state of an argument (or one of its children) is not OK.

An IllegalStateException would already be better.

But the best solution in such cases (failing cast) is a ClassCastException. That's the standard solution in JDK libraries, e.g. Collections#sort(..) or the TreeSet(Collection) constructor.

Even Comparable#compareTo(..) says @throws ClassCastException and not @throws IllegalArgumentException.
Comment 6 Lars Vogel CLA 2017-03-20 16:58:28 EDT
Thanks Markus for the feedback. 

I suggest to follow your suggestion but also give richer information what is causing this error.

Gerrit patch coming soon.
Comment 7 Eclipse Genie CLA 2017-03-20 17:00:30 EDT
New Gerrit change created: https://git.eclipse.org/r/93459
Comment 8 Eclipse Genie CLA 2017-03-20 17:21:34 EDT
New Gerrit change created: https://git.eclipse.org/r/93462
Comment 9 Markus Keller CLA 2017-03-21 11:36:28 EDT
As a test, I've replaced the GridData in Snippet38 with
	RowData data = new RowData();
 
- Original trace (on Oracle JDK 8):
Exception in thread "main" java.lang.ClassCastException: org.eclipse.swt.layout.RowData cannot be cast to org.eclipse.swt.layout.GridData
	at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:208)

- Proposed new trace:
Exception in thread "main" java.lang.ClassCastException: org.eclipse.swt.widgets.Table must use GridData as layout data. Currently using: RowData {}
	at org.eclipse.swt.layout.GridLayout.layout(GridLayout.java:211)


=> A CCE message that starts with an unrelated type is confusing. Let the CCE's message start with the original message and add additional infos at the end.

I wonder if there are real use cases where the class of the parent composite is really the thing you're looking for. If the code is so complicated that the normal CCE message is not enough, it's very likely that the parent is just a Composite. What you'd need in that case is the full parent chain, including the index of each child in its parent.getChildren() list.
Comment 10 Lars Vogel CLA 2017-03-31 07:08:47 EDT
FYI - this is still on my radar, I plan to return to this workitem next week.
Comment 11 Lars Vogel CLA 2017-04-20 14:33:12 EDT
(In reply to Lars Vogel from comment #10)
> FYI - this is still on my radar, I plan to return to this workitem next week.

Still busy with other stuff, sorry. I upload a revert and plan to look at this again for 4.8.
Comment 12 Eclipse Genie CLA 2017-04-20 14:35:34 EDT
New Gerrit change created: https://git.eclipse.org/r/95411
Comment 13 Lars Vogel CLA 2017-04-20 14:37:14 EDT
(In reply to Eclipse Genie from comment #12)
> New Gerrit change created: https://git.eclipse.org/r/95411

This reverts the original change.
Comment 15 Niraj Modi CLA 2018-05-14 05:42:24 EDT
Moving to 4.9, please re-target as required.
Comment 16 Lakshmi P Shanmugam CLA 2018-08-28 05:17:33 EDT
Resetting target, please re-target as required.
Comment 17 Eric Williams CLA 2019-08-27 14:46:12 EDT
Lars, do you still plan to work on this?
Comment 18 Lars Vogel CLA 2019-08-27 15:01:45 EDT
Would be nice to have this, please remind me again for M3
Comment 19 Alexander Kurtakov CLA 2019-11-14 03:08:47 EST
Too late for M3. Removing target, please readd it once there is patch.
Comment 20 Lars Vogel CLA 2020-06-12 06:24:14 EDT
Please reopen if you plan to provide a fix with a better error message.