Bug 152562 - [prefs] IJavaProject.setOption(..., null) does not work
Summary: [prefs] IJavaProject.setOption(..., null) does not work
Status: VERIFIED FIXED
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.2   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.4 M2   Edit
Assignee: Frederic Fusier CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2006-08-02 03:59 EDT by Martin Aeschlimann CLA
Modified: 2007-09-18 04:28 EDT (History)
1 user (show)

See Also:


Attachments
Proposed patch (65.88 KB, patch)
2007-08-20 06:08 EDT, Frederic Fusier CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Martin Aeschlimann CLA 2006-08-02 03:59:40 EDT
20060802

Currently, a call to IJavaProject.setOption(optionName, null) is a no-op: it just returns without changing anything.

However, the spec says:
Helper method for setting one option value only. Equivalent to <code>Map options = this.getOptions(false); map.put(optionName, optionValue); this.setOptions(map)</code>

It also maks sense to allow this. How can I otherwise remove a project option so that the workspace option is used again?
Comment 1 Frederic Fusier CLA 2006-08-02 05:21:40 EDT
IJavaProject.setOption spec'ed that this helper will behave as the put method of the map...

As the Map for JavaProject options is an Hashtable, you have to refer to Hashtable.put(Object,Object) method spec to know whether the value can be null or not:
     * Maps the specified <code>key</code> to the specified 
     * <code>value</code> in this hashtable. Neither the key nor the 
     * value can be <code>null</code>. <p>

Conclusion is that we do not expect neither a null key nor a null value for IJavaProject.setOption method. I definitely agree that it must be spec'ed more explicitely => I keep this bug to modify the spec but change summary and reduce severity 

Currently the way to remove an option on a JavaProject is to set it to its JavaCore value: project.setOption(optionName, JavaCore.getOption(optionName))
This is perhaps a convoluted way to do that, and perhaps we may add a removeOption on IJavaProject, but is there's a real need to change the API about this - except than have another helper?
Comment 2 Martin Aeschlimann CLA 2006-08-02 07:07:14 EDT
IJavaProject.getOptions returns 'Map' which leaves it open if null is supported in put or not. But you're right, the implementation returns an instance of Hashtable (why not a HashMap?)

I would suggest to allow null.
You mention that project.setOption(optionName, JavaCore.getOption(optionName)) results in inheritance. I think that's a major bug. If I want to set a project setting, it should be set on the project so it is really shared in the team.
For example if a project is set to 1.5 compliance. I want this setting really to be set on the project and not set to 'null' because my workspace setting happens to be 1.5 as well. My team's workspace might look different.

We haven't seen this problem because the compiler preference pages all use the preferences directly.

So I think we should clear this up in the spec and also fix the behaviour.
Comment 3 Frederic Fusier CLA 2006-08-02 07:30:13 EDT
(In reply to comment #2)
> IJavaProject.getOptions returns 'Map' which leaves it open if null is supported
> in put or not. But you're right, the implementation returns an instance of
> Hashtable (why not a HashMap?)
I think that's because it was intentional that null values were not allowed...

> 
> I would suggest to allow null.
I have to discuss about this with Philippe and Olivier if they remember why null values were avoided...

> You mention that project.setOption(optionName, JavaCore.getOption(optionName))
> results in inheritance. I think that's a major bug. If I want to set a project
> setting, it should be set on the project so it is really shared in the team.
> For example if a project is set to 1.5 compliance. I want this setting really
> to be set on the project and not set to 'null' because my workspace setting
> happens to be 1.5 as well. My team's workspace might look different.
It seems that I mixed default value and inherited one... This of course must be fixed and I've opened bug 152768 to track this issue.
> 
> We haven't seen this problem because the compiler preference pages all use the
> preferences directly.
> 
> So I think we should clear this up in the spec and also fix the behaviour.
> 
Agreed, I've put back your initial summary waiting discussion with Philippe and Olivier about this API change
Comment 4 Frederic Fusier CLA 2006-08-02 07:31:22 EDT
In my previous comment you should read bug 152578...
Comment 5 Frederic Fusier CLA 2007-03-16 05:07:53 EDT
Too risky to change this behavior at this late stage => defer post 3.3 as this bug finally does not block bug 152282 which has been fixed...
Comment 6 Frederic Fusier CLA 2007-06-21 11:02:39 EDT
Reopen as LATER is deprecated...
Comment 7 Frederic Fusier CLA 2007-08-20 06:08:51 EDT
Created attachment 76440 [details]
Proposed patch

Also includes fixes for bug 183623 and bug 152578.
Comment 8 Frederic Fusier CLA 2007-08-20 10:58:28 EDT
Released for 3.4M2 in HEAD stream.
Comment 9 Maxime Daniel CLA 2007-09-18 04:28:14 EDT
Test case is OptionTests#testBug152562.
Verified for 3.4 M2 using build I20070917-0010.