Bug 235354 - [ErrorHandling] [StatusHandling] WorkbenchStatusDialogManager#setStatusListLabelProvider() does not work
Summary: [ErrorHandling] [StatusHandling] WorkbenchStatusDialogManager#setStatusListLa...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.4   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: 3.5 M1   Edit
Assignee: Kevin McGuire CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks:
 
Reported: 2008-06-03 10:50 EDT by Krzysztof Daniel CLA
Modified: 2009-06-03 13:20 EDT (History)
3 users (show)

See Also:
Kevin_McGuire: review+


Attachments
Fix correcting javadoc and condition. (1.07 KB, patch)
2008-06-03 10:50 EDT, Krzysztof Daniel CLA
no flags Details | Diff
Fix (1.89 KB, patch)
2008-06-04 06:54 EDT, Krzysztof Daniel CLA
no flags Details | Diff
Fix (3.31 KB, patch)
2008-07-15 11:33 EDT, Krzysztof Daniel CLA
no flags Details | Diff
mylyn/context/zip (10.72 KB, application/octet-stream)
2008-07-15 11:33 EDT, Krzysztof Daniel CLA
no flags Details
Slightly modified fix (3.51 KB, patch)
2008-07-17 09:32 EDT, Krzysztof Daniel CLA
emoffatt: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Krzysztof Daniel CLA 2008-06-03 10:50:07 EDT
Created attachment 103325 [details]
Fix correcting javadoc and condition.

Build ID: I20080502-0100

By default parameter cannot be null so we do not have to say it again.
Condition checking if argument is null is incorrect.
Comment 1 Remy Suen CLA 2008-06-03 11:36:03 EDT
Personally, I think it's helpful to note that the argument cannot be null but I don't know what Platform/UI's standards are.
Comment 2 Kevin McGuire CLA 2008-06-03 14:52:37 EDT
(In reply to comment #1)
> Personally, I think it's helpful to note that the argument cannot be null but I
> don't know what Platform/UI's standards are.

Agree.

Boris, what's the "in" way to denote this?

Comment 3 Boris Bokowski CLA 2008-06-03 15:04:06 EDT
We actually have a document [1] that gives defaults (if we don't say anything, null is not allowed). However, typical clients have so many things to worry about that we should help them where we can, i.e. we should not make it a requirement to read the document in order to understand our API contracts.

+1 for making constraints about null explicit.

But also +1 for changing the manually thrown NPE into an Assert, or even better into an IllegalArgumentException: You want to make it clear whose fault it is when an exception happens. An NPE is usually interpreted as an error in the callee, whereas an IllegalArgumentException clearly points to the caller as the culprit.
Comment 5 Remy Suen CLA 2008-06-03 15:33:35 EDT
(In reply to comment #3)
> But also +1 for changing the manually thrown NPE into an Assert, or even better
> into an IllegalArgumentException: You want to make it clear whose fault it is
> when an exception happens. An NPE is usually interpreted as an error in the
> callee, whereas an IllegalArgumentException clearly points to the caller as the
> culprit.

If we want an IAE then I guess it should be changed to call isLegal instead of isNotNull.
Comment 6 Krzysztof Daniel CLA 2008-06-04 06:54:47 EDT
Created attachment 103531 [details]
Fix

Javadoc untouched.
Test case created.
Condition corrected - please note that the most important issue here is invalid condition (method argument is not checked in original code), therefore I'd like to see this included in current RC or in 3.4.1.
Comment 7 Krzysztof Daniel CLA 2008-07-15 11:33:40 EDT
Created attachment 107477 [details]
Fix

Ok, back to work.

I would like to point that the problem with assertion message and javadoc is not the most important thing here.

Note that the condition statusListLabelProvider != null is not checking the parameter, but some internal field.

There are two tests that should be passed:
testNullLabelProvider - to be sure that one cannot pass null there
testNonNullLabelProvider - to be sure that custom label provider is really used

Kevin, 
could you review?
Comment 8 Krzysztof Daniel CLA 2008-07-15 11:33:43 EDT
Created attachment 107478 [details]
mylyn/context/zip
Comment 9 Kevin McGuire CLA 2008-07-16 15:59:18 EDT
(In reply to comment #7)

> Note that the condition statusListLabelProvider != null is not checking the
> parameter, but some internal field.

D'oh right!  Its checking the existing field, not the parameter which will be assigned to the field.

> Kevin, 
> could you review?

Comments:

1) Minor: javadoc should be "<code>null</code>"
2) Why are you doing 
  Assert.isLegal(labelProvider != null) 
vs.
  Assert.isNotNull(labelProvider);

Assert.isNotNull() is more explicit/specific (i.e. matches the comment).  It's also I believe the "in" way; if you look for references of each you'll notice 3x isNotNull vs. isLegal. (note: reminder that if we change this then test must also be changed to match)

Comment 10 Krzysztof Daniel CLA 2008-07-17 09:32:00 EDT
Created attachment 107733 [details]
Slightly modified fix

about IAE: I was inspired by comment 3:
"You want to make it clear whose fault it is when an exception happens. An NPE is usually interpreted as an error in the callee, whereas an IllegalArgumentException clearly points to the caller as the culprit".
As I said - I think that a kind of exception is a subject for rather academic discussion, so feel free to change it.
Comment 11 Kevin McGuire CLA 2008-07-17 10:45:45 EDT
I think you can regard isNotNull() as a more precise isLegal().  Its a subset of the cases.  Boris' comment was that an NPE is usually a system error (our bug), while as both isNotNull() and isLegal() identify the parameter as not matching the specification (the caller's bug).

I'm not sure why Boris specifically mentioned IllegalArgumentException vs. Assert.  Its true that isLegal() throws IllegalArgumentException, and isNotNull() throws AssertionFailedException(), but I'm not sure that makes a practical difference.  isNotNull seems to me the right Assert but I'm not really fussed either way, they both have the right quality.
Comment 12 Kevin McGuire CLA 2008-07-17 11:26:47 EDT
Spoke with Paul about best practice on isLegal(param != null) or isNotNull(param).  He tends to the former since it explicitly states its for argument exceptions.  

In practice though it looks to me we always use the latter.  In fact I only found 47 references to isLegal(* != null) and those were all in texteditor!

I'm fine with either.
Comment 13 Kevin McGuire CLA 2008-07-17 11:43:04 EDT
Released to HEAD.  Thanks for the patch and test.
Comment 14 Krzysztof Daniel CLA 2008-08-12 04:03:32 EDT
verified by running tests (cause there is test case) and by code inspection