Bug 154688 - [Viewers] [JFace] Use exceptions instead of asserts when testing API parameters
Summary: [Viewers] [JFace] Use exceptions instead of asserts when testing API parameters
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.2   Edit
Hardware: All All
: P3 enhancement (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2006-08-22 08:49 EDT by Michael Moser CLA
Modified: 2019-09-06 15:30 EDT (History)
2 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Michael Moser CLA 2006-08-22 08:49:38 EDT
There are many places where JFace uses org.eclipse.jface.util.Assert. While I fully agree that Asserts are a fine thing if they are used to verify programming assumptions and internal consistency within a framework, they are a lousy way to check API parameters passed in! If such an assert fails a programmer gets little or no clue what is wrong and has to dig into JFace's source code to find out, why things fail. For the latter purpose please throw telling exceptions (like NullPointerException or IllegalArgumentException with some short msg.) instead of doing assertions!

Example: I just got this:
-------------------------------
org.eclipse.jface.util.Assert$AssertionFailedException: Assertion failed: 
	at org.eclipse.jface.util.Assert.isTrue(Assert.java:182)
	at org.eclipse.jface.util.Assert.isTrue(Assert.java:167)
	at org.eclipse.jface.viewers.AbstractTreeViewer.assertContentProviderType(AbstractTreeViewer.java:2086)
	at org.eclipse.jface.viewers.TreeViewer.assertContentProviderType(TreeViewer.java:761)
	at org.eclipse.jface.viewers.StructuredViewer.setContentProvider(StructuredViewer.java:1518)
	at org.eclipse.jface.viewers.AbstractTreeViewer.setContentProvider(AbstractTreeViewer.java:2082)
	at myplugin.AnalysisView.createViewer(AnalysisView.java:263)
...
-------------------------------

In my project I had just decided to change my view from a TableViewer to use a TreeViewer (formerly called a TableTreeViewer) instead and as turned out (but only by looking at the JFace source) I had forgotten to adapt the view's content provide to implement ITreeContentProvider or ITreePathContentProvider (instead of IStructuredContentProvider).

If there would be an IllegalArgumentException("content provider not implementing ITreeContentProvider nor ITreePathContentProvider") or similar the reason for the exception would have been immediately clear to me.

Michael
Comment 1 Boris Bokowski CLA 2006-08-22 11:47:05 EDT
I agree that throwing an IllegalArgumentException would be better in this case.
Comment 2 Boris Bokowski CLA 2009-11-26 09:54:34 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 3 Eclipse Webmaster CLA 2019-09-06 15:30:13 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.