Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 387898 - Wrong preference node created when starting org.eclipse.jdt.debug.ui plugin
Summary: Wrong preference node created when starting org.eclipse.jdt.debug.ui plugin
Status: CLOSED WONTFIX
Alias: None
Product: Equinox
Classification: Eclipse Project
Component: Compendium (show other bugs)
Version: 3.8.1 Juno   Edit
Hardware: All All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Szymon Ptaszkiewicz CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
: 397290 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-08-23 09:51 EDT by Szymon Ptaszkiewicz CLA
Modified: 2019-09-17 00:26 EDT (History)
9 users (show)

See Also:
sptaszkiewicz: review? (john.arthorne)


Attachments
Patch v.0.1 (1.72 KB, patch)
2012-12-19 15:15 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff
Test v.0.1 (2.89 KB, patch)
2012-12-19 15:15 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff
Patch v.0.2 (3.54 KB, patch)
2013-01-07 11:27 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff
Test v.0.2 (2.93 KB, patch)
2013-01-07 11:27 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff
Patch v.0.2 (2.80 KB, patch)
2013-01-07 11:32 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff
Patch v.0.3 (3.76 KB, patch)
2013-02-12 11:31 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff
Test v.0.3 (5.28 KB, patch)
2013-02-12 11:38 EST, Szymon Ptaszkiewicz CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Szymon Ptaszkiewicz CLA 2012-08-23 09:51:09 EDT
Build id: I20120814-0800

When starting org.eclipse.jdt.debug.ui plugin during exception inspector initialization a new project preference node /project/org.eclipse.jdt.debug is created. This conflicts with the purpose of project preferences where the hierarchy is /<scope>/<project_in_workspace>/<plugin_that_stores_preferences> and this is somewhat confusing how it is possible that without any project in workspace we get a node that corresponds to org.eclipse.jdt.debug project stored in workspace. See the output from the Preferences Spy view to observe changing preferences hierarchy.
Comment 1 Dani Megert CLA 2012-08-23 10:09:59 EDT
Is there any real/visible impact?
Comment 2 Szymon Ptaszkiewicz CLA 2012-08-23 10:53:48 EDT
(In reply to comment #1)
> Is there any real/visible impact?

I have not found any apart from broken hierarchy.
Comment 3 Michael Rennie CLA 2012-12-18 08:57:28 EST
What is the value of the preference? We have only one reference to ProjectScope in all of JDT debug and it is only used to look up a builder setting.
Comment 4 Szymon Ptaszkiewicz CLA 2012-12-18 09:57:15 EST
(In reply to comment #3)
> What is the value of the preference? We have only one reference to
> ProjectScope in all of JDT debug and it is only used to look up a builder
> setting.

There is no value set, only empty node is created. To reproduce:
1. Open new workspace.
2. Open Preferences Spy view and verify there is no child node for /project.
3. Open Run > Debug configurations...
4. Create new Java Application configuration.
5. Close the dialog.
6. Refresh Preferences Spy view by using "Collapse All".
=> Verify there are two new nodes added under /project: org.eclipse.debug.core and org.eclipse.jdt.debug.
Comment 5 Michael Rennie CLA 2012-12-18 16:20:44 EST
(In reply to comment #4)
> (In reply to comment #3)
> > What is the value of the preference? We have only one reference to
> > ProjectScope in all of JDT debug and it is only used to look up a builder
> > setting.
> 
> There is no value set, only empty node is created. To reproduce:
> 1. Open new workspace.
> 2. Open Preferences Spy view and verify there is no child node for /project.
> 3. Open Run > Debug configurations...
> 4. Create new Java Application configuration.
> 5. Close the dialog.
> 6. Refresh Preferences Spy view by using "Collapse All".
> => Verify there are two new nodes added under /project:
> org.eclipse.debug.core and org.eclipse.jdt.debug.

These are coming from calls to the preference service to ask for preferences.

The debug.core one comes from:

String preferred = Platform.getPreferencesService().getString(DebugPlugin.getUniqueIdentifier(), LaunchManager.PREF_PREFERRED_DELEGATES, IInternalDebugCoreConstants.EMPTY_STRING, null);

and the jdt.debug one comes from:

boolean doit = Platform.getPreferencesService().getBoolean(
				JDIDebugPlugin.getUniqueIdentifier(), 
				IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION, 
				false, 
				null);

debugging through the code and it looks like if you ask for a node that does not exist a new empty node is created - in the platform resources code, not debug.

Moving to platform resources for comment. Is there a way we should be asking for preferences that will not create empty nodes?
Comment 6 Szymon Ptaszkiewicz CLA 2012-12-19 05:38:55 EST
(In reply to comment #5)
> The debug.core one comes from:
> 
> String preferred =
> Platform.getPreferencesService().getString(DebugPlugin.getUniqueIdentifier(),
> LaunchManager.PREF_PREFERRED_DELEGATES,
> IInternalDebugCoreConstants.EMPTY_STRING, null);
> 
> and the jdt.debug one comes from:
> 
> boolean doit = Platform.getPreferencesService().getBoolean(
> 				JDIDebugPlugin.getUniqueIdentifier(), 
> 				IJDIPreferencesConstants.PREF_OPEN_INSPECT_POPUP_ON_EXCEPTION, 
> 				false, 
> 				null);
> 
> debugging through the code and it looks like if you ask for a node that does
> not exist a new empty node is created - in the platform resources code, not
> debug.
> 
> Moving to platform resources for comment. Is there a way we should be asking
> for preferences that will not create empty nodes?

The #node method must create new node as this is part of preferences API. The point is that you should not be looking for your preference in project scope, because it does not seem to be project related. In other words, passing 'null' as the last argument in the calls above does not seem to be right.
Comment 7 Szymon Brandys CLA 2012-12-19 06:59:43 EST
As Szymon said, the context should be something like:
new IScopeContext[]{Instance.INSTANCE, Configuration.INSTANCE}
unless you really want to look int the project scope. Then the context would be:
new IScopeContext[] { new ProjectScope(project)}
Comment 8 Michael Rennie CLA 2012-12-19 10:03:21 EST
(In reply to comment #7)
> As Szymon said, the context should be something like:
> new IScopeContext[]{Instance.INSTANCE, Configuration.INSTANCE}
> unless you really want to look int the project scope. Then the context would
> be:
> new IScopeContext[] { new ProjectScope(project)}

I made a test change to supply the instance scope which makes no difference, the project node is created anyway - see PreferencesService#getNodes:

if (!found) {
						Preferences node = getRootNode().node(scopeString).node(qualifier);
						if (childPath != null)
							node = node.node(childPath);
						result.add(node);
					}

We are using the preferences API as is allowed, I am inclined to mark this as wontfix, unless resources wants to make some changes to prevent the service from creating dead nodes.
Comment 9 Szymon Ptaszkiewicz CLA 2012-12-19 12:56:34 EST
(In reply to comment #8)
> We are using the preferences API as is allowed, I am inclined to mark this
> as wontfix, unless resources wants to make some changes to prevent the
> service from creating dead nodes.

I guess we can help here, but the actual fix needs to be done in the preferences bundle. Moving to Equinox/Compendium. Patch will follow.
Comment 10 Szymon Ptaszkiewicz CLA 2012-12-19 15:15:23 EST
Created attachment 224928 [details]
Patch v.0.1
Comment 11 Szymon Ptaszkiewicz CLA 2012-12-19 15:15:51 EST
Created attachment 224929 [details]
Test v.0.1
Comment 12 Szymon Ptaszkiewicz CLA 2012-12-19 15:27:03 EST
John, can you review?
Comment 14 Dani Megert CLA 2013-01-03 09:29:05 EST
The fix is not good. It causes preferences to be 'null' now, see e.g. 397290.

I verified that all works fine with the old version of PreferenceService.
Comment 15 Dani Megert CLA 2013-01-03 09:30:47 EST
*** Bug 397290 has been marked as a duplicate of this bug. ***
Comment 16 John Arthorne CLA 2013-01-03 14:37:12 EST
Yes the fix is bad because in the case of default scope, the node is only initialized at the moment it is created. So just because the node does not exist does not mean it will not have any values once created. I have reverted the change:

http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/?id=82bd6fb64c976d01579a027852569486ce721df3

This commit reverts Szymon's tests, and introduces a new regression test to verify that the new regression is fixed:

http://git.eclipse.org/c/platform/eclipse.platform.runtime.git/commit/?id=22612df8dbfd9c7ef978673f1c69549037f26871
Comment 17 Dani Megert CLA 2013-01-04 03:12:11 EST
Verified in N20130103-2000 that the NPE is gone.
Comment 18 Szymon Ptaszkiewicz CLA 2013-01-07 10:38:54 EST
The root cause of regression is that DefaultPreferences#nodeExists does not take into consideration possibility that node may get be created programatically in initializer. We had similar problem with #nodeExists in bug 388004, so I guess the right fix would be to extend DefaultPreferences#nodeExists to cover nodes created in runtime. Since initializers can be 3rd party code, all we can do is to try to run them inside #nodeExists and then check if the node got created. I tried this approach and it fixes this bug. The new regression test added by John also passes with this approach. I will attach new cumulative patches shortly.
Comment 19 Szymon Ptaszkiewicz CLA 2013-01-07 11:27:15 EST
Created attachment 225289 [details]
Patch v.0.2
Comment 20 Szymon Ptaszkiewicz CLA 2013-01-07 11:27:32 EST
Created attachment 225290 [details]
Test v.0.2
Comment 21 Szymon Ptaszkiewicz CLA 2013-01-07 11:32:14 EST
Created attachment 225292 [details]
Patch v.0.2

Previously attached patch was not the one I wanted to upload.
Comment 22 Thomas Watson CLA 2013-01-31 09:21:56 EST
Moving this to M6.  John is this something you could review and release after M5?
Comment 23 Szymon Ptaszkiewicz CLA 2013-02-11 12:25:42 EST
DefaultPreferences#nodeExists needs some more love because it still misses preferences that can be set via preferences.ini file inside bundles and we definitely must not break those cases. I will adjust the patch.
Comment 24 Szymon Ptaszkiewicz CLA 2013-02-12 11:31:40 EST
Created attachment 226931 [details]
Patch v.0.3

There are no additional changes in PreferencesService class compared to the fix that was previously released. The only additional modification is in the DefaultPreferences#nodeExists method.
Comment 25 Szymon Ptaszkiewicz CLA 2013-02-12 11:38:34 EST
Created attachment 226934 [details]
Test v.0.3

Apart from changes that were previously released PreferencesServicesTest contains additional test for the case described in comment 23. I added new "empty" plugin for this test to make sure that the new test does not depend on other plugins and nodes. If you agree with adding this new plugin, it will require pom.xml for CBI compatibility. For now, I have skipped it so that patches contain only relevant changes.
Comment 26 Szymon Ptaszkiewicz CLA 2013-02-12 11:44:25 EST
Resetting review flag since previous fix was reverted. The new fix contains previous fix and additional changes that cover regression from comment 14 and comment 23.
Comment 27 Thomas Watson CLA 2013-03-18 14:44:16 EDT
Where are we at with this bug?  I assume it is not addressed in M6.  I am marking for M7 for now.
Comment 28 Szymon Ptaszkiewicz CLA 2013-03-19 07:16:37 EDT
(In reply to comment #27)
> Where are we at with this bug?

Patches are up to date and waiting for review.
Comment 29 John Arthorne CLA 2013-04-19 15:15:23 EDT
I get two test failures with this patch applied:

org.eclipse.core.tests.internal.preferences.TestBug388004
testBug(org.eclipse.core.tests.internal.preferences.TestBug388004)
junit.framework.AssertionFailedError: This node exists in pluginCustomization file.

org.eclipse.core.tests.internal.preferences.TestBug380859
testBug(org.eclipse.core.tests.internal.preferences.TestBug380859)
junit.framework.ComparisonFailure: expected:<[v1]> but was:<[not_found]>

I'm having a hard time understanding why we actually want to fix this. Preference initialization is a complicated piece of code and this patch alters the init order based on when a client calls nodeExists. There is no user visible bug or other apparent benefit of changing this from what I can see.
Comment 30 Dani Megert CLA 2013-04-22 05:41:06 EDT
(In reply to comment #29)
> I get two test failures with this patch applied:
> 
> org.eclipse.core.tests.internal.preferences.TestBug388004
> testBug(org.eclipse.core.tests.internal.preferences.TestBug388004)
> junit.framework.AssertionFailedError: This node exists in
> pluginCustomization file.
> 
> org.eclipse.core.tests.internal.preferences.TestBug380859
> testBug(org.eclipse.core.tests.internal.preferences.TestBug380859)
> junit.framework.ComparisonFailure: expected:<[v1]> but was:<[not_found]>
> 
> I'm having a hard time understanding why we actually want to fix this.
> Preference initialization is a complicated piece of code and this patch
> alters the init order based on when a client calls nodeExists. There is no
> user visible bug or other apparent benefit of changing this from what I can
> see.

I agree. Suggest to close as WONTFIX, but definitely -1 for Kepler.
Comment 31 Szymon Ptaszkiewicz CLA 2013-04-22 05:45:28 EDT
(In reply to comment #29)
> I get two test failures with this patch applied:
> 
> org.eclipse.core.tests.internal.preferences.TestBug388004
> testBug(org.eclipse.core.tests.internal.preferences.TestBug388004)
> junit.framework.AssertionFailedError: This node exists in
> pluginCustomization file.
> 
> org.eclipse.core.tests.internal.preferences.TestBug380859
> testBug(org.eclipse.core.tests.internal.preferences.TestBug380859)
> junit.framework.ComparisonFailure: expected:<[v1]> but was:<[not_found]>

Bug 380859 was fixed last Friday so it was not there when the patch was prepared. I have just applied the patch on current master branch and run the whole runtime suite and I don't see any failures. John, can you double-check that?
Comment 32 Thomas Watson CLA 2013-05-01 11:25:04 EDT
Deferring to Luna.
Comment 33 Szymon Ptaszkiewicz CLA 2013-10-04 10:32:22 EDT
Bug 418046 shows an example where creating empty preference nodes may result in removing some of the preferences.

The attached patches still apply on the master branches. Could we review/release for Luna early in the cycle?
Comment 34 Szymon Ptaszkiewicz CLA 2014-01-14 11:24:07 EST
Is there any chance to have this reviewed and pushed for Luna? The bug is assigned to me but I cannot push it by myself.
Comment 35 Thomas Watson CLA 2014-01-14 12:10:07 EST
CC'ing John since I don't think he has seen this review request.
Comment 36 Thomas Watson CLA 2014-05-14 11:14:58 EDT
Moving to Mars, would be good to get a review by John.
Comment 37 Szymon Ptaszkiewicz CLA 2014-07-22 09:36:22 EDT
Converted to Gerrit change:

https://git.eclipse.org/r/#/c/30246/
https://git.eclipse.org/r/#/c/30247/
Comment 38 Dani Megert CLA 2015-08-10 03:13:27 EDT
M1 has left the station.
Comment 39 Dani Megert CLA 2015-10-27 10:17:45 EDT
(In reply to Dani Megert from comment #38)
> M1 has left the station.

and M2, and M3 on Friday.
Comment 40 Dani Megert CLA 2015-11-24 10:29:57 EST
From John:

"
Hi Szymon,


My opinion hasn't changed since my comment two years ago in the bug:


"I'm having a hard time understanding why we actually want to fix this. Preference initialization is a complicated piece of code and this patch alters the init order based on when a client calls nodeExists. There is no user visible bug or other apparent benefit of changing this from what I can see."

I think we should close as WONTFIX and move on to something with more visible impact and user value.
John
"

I completely agree with that. Closing as WONTFIX.
Comment 41 Szymon Ptaszkiewicz CLA 2015-11-24 11:20:00 EST
(In reply to Dani Megert from comment #40)

This is a good way to tell your contributors to stop contributing. Well done.
Comment 43 Thomas Watson CLA 2016-10-07 08:51:01 EDT
(In reply to Eclipse Genie from comment #42)
> Gerrit change https://git.eclipse.org/r/30246 was merged to [master].
> Commit:
> http://git.eclipse.org/c/equinox/rt.equinox.bundles.git/commit/
> ?id=92ae5195ee7a7685524798f74948b8fcbfeb7ccd

Seems we have decided to fix this.  Reflecting the decision in the bug resolution.
Comment 44 Szymon Ptaszkiewicz CLA 2016-10-24 03:20:40 EDT
Reopening because the bug is not done yet - you need to push both changes but only the first one was merged. Two changes are needed because tests live in a different repository than the code being tested.

(In reply to Szymon Ptaszkiewicz from comment #37)
> Converted to Gerrit change:
> 
> https://git.eclipse.org/r/#/c/30246/
> https://git.eclipse.org/r/#/c/30247/
Comment 45 Thomas Watson CLA 2016-10-24 10:05:24 EDT
(In reply to Szymon Ptaszkiewicz from comment #44)
> Reopening because the bug is not done yet - you need to push both changes
> but only the first one was merged. Two changes are needed because tests live
> in a different repository than the code being tested.
> 
> (In reply to Szymon Ptaszkiewicz from comment #37)
> > Converted to Gerrit change:
> > 
> > https://git.eclipse.org/r/#/c/30246/
> > https://git.eclipse.org/r/#/c/30247/

I rebased the tests, but now it seems we have a consistent failure (not related to the test changes in the review since the failure is in master).  See bug 506447.
Comment 47 Thomas Watson CLA 2016-11-02 16:31:13 EDT
(In reply to Eclipse Genie from comment #46)
> Gerrit change https://git.eclipse.org/r/30247 was merged to [master].
> Commit:
> http://git.eclipse.org/c/platform/eclipse.platform.runtime.git/commit/
> ?id=9f2e003e61774d56adf1716c8c0faa293240c19a

Finally should be done now.
Comment 48 Sergey Prigogin CLA 2017-01-26 16:24:05 EST
The change made in https://git.eclipse.org/r/#/c/30246/5/bundles/org.eclipse.equinox.preferences/src/org/eclipse/core/internal/preferences/DefaultPreferences.java is invalid since the preference node can be left in a state when runtime defaults are applied but product and command line customizations that are supposed to override the runtime defaults are not applied.

This is causing bug 511138.
Comment 50 Eclipse Genie CLA 2019-09-17 00:26:12 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.

--
The automated Eclipse Genie.