Community
Participate
Working Groups
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.
New Gerrit change created: https://git.eclipse.org/r/92393
Gerrit change https://git.eclipse.org/r/92393 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=c02edb84db60f1a24a123b065dcda3dcf630785d
Pushed. Test case that verifies this exception properly occurs has to be added.
New Gerrit change created: https://git.eclipse.org/r/93399
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.
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.
New Gerrit change created: https://git.eclipse.org/r/93459
New Gerrit change created: https://git.eclipse.org/r/93462
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.
FYI - this is still on my radar, I plan to return to this workitem next week.
(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.
New Gerrit change created: https://git.eclipse.org/r/95411
(In reply to Eclipse Genie from comment #12) > New Gerrit change created: https://git.eclipse.org/r/95411 This reverts the original change.
Gerrit change https://git.eclipse.org/r/95411 was merged to [master]. Commit: http://git.eclipse.org/c/platform/eclipse.platform.swt.git/commit/?id=1dfb48242d897fb687a2db38b34caef81c8282b4
Moving to 4.9, please re-target as required.
Resetting target, please re-target as required.
Lars, do you still plan to work on this?
Would be nice to have this, please remind me again for M3
Too late for M3. Removing target, please readd it once there is patch.
Please reopen if you plan to provide a fix with a better error message.