Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 285235 - Logic error in DirectorApplication
Summary: Logic error in DirectorApplication
Status: RESOLVED FIXED
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: p2 (show other bugs)
Version: 3.5   Edit
Hardware: PC Windows XP
: P3 normal (vote)
Target Milestone: 3.6 M2   Edit
Assignee: P2 Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2009-07-30 17:28 EDT by James D. Miles CLA
Modified: 2009-08-20 14:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description James D. Miles CLA 2009-07-30 17:28:31 EDT
In the initializeServices method, line 420 of 3.5, we have 
if (profileId == null)
    preservedProfile = System.setProperty(PROP_P2_PROFILE, profileId);
else
    System.getProperties().remove(PROP_P2_PROFILE);

If profileId is actually null we will throw a NullPointerException. I think this wasn't discovered because it is not possible to get null with the current code.

Line 675 of restoreServices seems to have the correct implementation.
Comment 1 DJ Houghton CLA 2009-08-17 17:07:16 EDT
Fixed.
Comment 2 Michal Ruzicka CLA 2009-08-20 07:24:55 EDT
The mentioned piece of code in its original form had the unpleasant consequence of not setting the preservedProfile in case profileId != null, as in that case the return value of:
    System.getProperties().remove(PROP_P2_PROFILE);
was ignored, which caused P2 not to be re-initialized properly later on.

So I suggest to improve the (already fixed) code in the following way:

if (profileId != null)
    preservedProfile = System.setProperty(PROP_P2_PROFILE, profileId);
else
    preservedProfile = (String)System.getProperties().remove(PROP_P2_PROFILE);

Note that I realize that the else branch is currently not reachable, this is just for the case it became reachable by changes in other parts of the class's code.
The other option is to throw an exception in the else branch to make it apparent that it's really not to be reached.
Comment 3 DJ Houghton CLA 2009-08-20 14:16:38 EDT
Change released.