Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 358681

Summary: Show Null Array Entries in Variables view is broken
Product: [Eclipse Project] JDT Reporter: Rob Griffin <rob.griffin>
Component: DebugAssignee: JDT-Debug-Inbox <jdt-debug-inbox>
Status: CLOSED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: curtis.windatt.public, daniel_megert, jiangk, Michael_Rennie, pwebster
Version: 3.8   
Target Milestone: ---   
Hardware: PC   
OS: Windows 7   
Whiteboard: stalebug
Attachments:
Description Flags
fix
none
Workaround patch to sync action and Preference
none
pref init
none
Workaround patch to sync action and Preference in Variables and Expression View none

Description Rob Griffin CLA 2011-09-22 22:47:50 EDT
Build Identifier: I20110620-1631

When examining an array in the Variables view null entries are displayed even though the Show null array entries menu item is unchecked. 

And it is not possible to check the menu item either.

My environment is a 64 bit Eclipse using Java 7 on Windows 7 debugging a 32 bit application running on Java 6.

Reproducible: Always

Steps to Reproduce:
1. Set a breakpoint where an array variable is in scope.
2. Run to the breakpoint.
3. Examine the array variable.
4. Null entries are displayed.
Comment 1 Michael Rennie CLA 2013-02-19 11:59:08 EST
Here is a simple snippet to test with.

public class ArrayView {
	public static void main(String[] args) {
		String[] strings = {null, null, null, null};
		System.out.println(strings.length); //BP here
	}
}

I did not notice that the filtering was not working, but I did find that you have to click the menu item a few times to get it to respond.

Steps:
1. new workspace + project
2. use the given snippet
3. debug it
4. toggle the Show Null Entries menu item
5. notice you have to click it a few times

Looking at the code it appears that it saves the preference but does not correctly look it up, instead relying on the state of the action delegate after the fact. I tried updating the code to ask for the saved pref instead of using the action, but there also seems to be a bug in there where the wrong preference is looked up - we always end up getting the default value instead of the one we saved, this is especially annoying because the state of the (action)filter is saved per view that uses it (the var and expressions view can set it separately from each other).

This just seems to be completely broken.
Comment 2 Michael Rennie CLA 2013-05-08 12:01:27 EDT
Created attachment 230660 [details]
fix

The patch corrects the pref lookup and adds a sanity check to avoid re-setting the state of the action if the property has not actually changed
Comment 3 Michael Rennie CLA 2013-05-08 12:01:55 EDT
Curtis, please review
Comment 4 Curtis Windatt CLA 2013-05-08 14:52:49 EDT
+1 works great, remembers the setting correctly after restart.

http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=6b0aee2c137a32718e015329035672c62a1e1751
Comment 5 Dani Megert CLA 2013-05-24 06:16:50 EDT
Verified in I20130523-1400: still broken:

1. start new workspace
2. open Variables view
3. toggle Java > Show Null Array Entries
4. open the menu again
==> not toggled

Another test case:
1. enable the option
2. exit & restart
3. start debugging the snippet from comment 1
==> null values are shown, but when opening the menu, the option seems off
Comment 6 Curtis Windatt CLA 2013-05-24 11:36:26 EDT
When running in a target workspace (new workspace location), it works fine for me.  However, trying the steps in a host Eclipse application on a new workspace the options are not checked after clicking them.

This happens for all of the actions in the Java menu.
Comment 7 Curtis Windatt CLA 2013-05-24 11:36:43 EDT
*** Bug 234357 has been marked as a duplicate of this bug. ***
Comment 8 Sarika Sinha CLA 2014-04-01 07:42:34 EDT
Strange behaviour is observed. If I Check the "Show Null Array Entries" and exit and restart with Variables view. The option will be unchecked in the Variable View but Preference gives back the value true for the option. If I change the view to Expression View, there I see init of ShowNullArrayEntriesAction getting called and both the check and preference value matches. 
Other way round, if I start with expression view after restart, thing doesn't work and things gets initialized properly in Variables View.
Comment 9 Sarika Sinha CLA 2014-04-02 07:10:21 EDT
Created attachment 241503 [details]
Workaround patch to sync action and Preference

There appears to be an issue with compatibility layer of e4 which is not invoking lifecycle methods for View Actions if the the view is visible in the workspace after launch. If we switch to the view, the View actions are properly initialized. As we have plans to move to Command framework , I am attaching a workaround patch which syncs the Action checked state and preference state. Same thing happens for all the Java Actions, so we will have to do the same thing for all of them.So this patch keeps the state in sync after adding the required filter in JavaContentProviderFilter but the flaw is that preference is maintained only for the session. After restart of workspace , Action will be set back to Checked state always.
Comment 10 Michael Rennie CLA 2014-04-04 16:56:39 EDT
(In reply to Sarika Sinha from comment #9)
> Created attachment 241503 [details]
> Workaround patch to sync action and Preference
> 
> There appears to be an issue with compatibility layer of e4 which is not
> invoking lifecycle methods for View Actions if the the view is visible in
> the workspace after launch. If we switch to the view, the View actions are
> properly initialized. As we have plans to move to Command framework , I am
> attaching a workaround patch which syncs the Action checked state and
> preference state. Same thing happens for all the Java Actions, so we will
> have to do the same thing for all of them.So this patch keeps the state in
> sync after adding the required filter in JavaContentProviderFilter but the
> flaw is that preference is maintained only for the session. After restart of
> workspace , Action will be set back to Checked state always.

Took a quick look at the patch, and was wondering why you didn't add:

prefStore.setValue(IDebugUIConstants.ID_VARIABLE_VIEW + "." + IJDIPreferencesConstants.PREF_SHOW_NULL_ARRAY_ENTRIES, true);//$NON-NLS-1$
prefStore.setValue(IDebugUIConstants.ID_EXPRESSION_VIEW + "." + IJDIPreferencesConstants.PREF_SHOW_NULL_ARRAY_ENTRIES, false);//$NON-NLS-1$

to JDIDebugUIPrefereceInitializer instead if the DebugOptionsManager? It looks like the initialization in there is bogus anyway:

store.setDefault(IJDIPreferencesConstants.PREF_SHOW_NULL_ARRAY_ENTRIES, true);

since those actions look up the preference with a combined view id.
Comment 11 Sarika Sinha CLA 2014-04-07 01:03:14 EDT
Only one reason, I added it to DebugOptionsManager is that we should remember to remove it after we have moved to commands framework. As we have debuggerActive also used there which should be knocked off with a better framework.

JDIDebugUIPrefereceInitializer generally initializes the default value.
Comment 12 Michael Rennie CLA 2014-04-28 15:12:27 EDT
Created attachment 242415 [details]
pref init

Here is what I was thinking of with the pref init.
Comment 13 Sarika Sinha CLA 2014-04-30 02:23:39 EDT
(In reply to Michael Rennie from comment #12)
> Created attachment 242415 [details]
> pref init
> 
> Here is what I was thinking of with the pref init.

This does not resolve the scenario :
1. Disable the "Show Null Array Entries" from Variable view.
2. Debug the program, filter works fine.
3. Exit and Restart.
4. Debug the program, Null Values are not displayed( that's what is store in the pref) but Variable View shows that "Show Null Array Entries" Option is enabled (As we are setting that as true in the start)

to handle this I had added the pref store updation in JavaDebugOptionsManager
Comment 14 Michael Rennie CLA 2014-05-12 13:52:30 EDT
(In reply to Sarika Sinha from comment #13)
> (In reply to Michael Rennie from comment #12)
> > Created attachment 242415 [details]
> > pref init
> > 
> > Here is what I was thinking of with the pref init.
> 
> This does not resolve the scenario :
> 1. Disable the "Show Null Array Entries" from Variable view.
> 2. Debug the program, filter works fine.
> 3. Exit and Restart.
> 4. Debug the program, Null Values are not displayed( that's what is store in
> the pref) but Variable View shows that "Show Null Array Entries" Option is
> enabled (As we are setting that as true in the start)
> 
> to handle this I had added the pref store updation in JavaDebugOptionsManager

Yes, I see this too, but it seems only if the variables view is not the top view in its stack:

1. do steps 1, 2 mentioned above
2. make the var view not the top view in its stack
3. exit / restart
4. re-debug, menu item is checked when you bring the var view into focus.

Oddly enough at step 4 it looks up the correct pref, sets the action state to false (unchecked), but it still shows up as checked.
Comment 15 Curtis Windatt CLA 2014-05-12 16:55:15 EDT
Using Sarika's patch, I still see one issue:
1) Have expressions view open with 'show null entries' unchecked
2) Restart Eclipse
3) Open expression view menu, 'show null entries' is checked!

When I launch the example program and inspect an item, null entries are shown in the popup.
If I use Ctrl-Shift-I to move the inspect to the expressions view, null entries are NOT shown and the menu item is correctly set unchecked.

I expected the change to the plugin.xml extension would have avoided this. You can also reproduce in a new workspace, just opening the expressions view.  Perhaps the menu doesn't differentiate between what view it is in until content is added to the view and the filter applied?
Comment 16 Sarika Sinha CLA 2014-05-13 04:32:39 EDT
(In reply to Michael Rennie from comment #14)
> (In reply to Sarika Sinha from comment #13)
> > (In reply to Michael Rennie from comment #12)
> > > Created attachment 242415 [details]
> > > pref init
> > > 
> > > Here is what I was thinking of with the pref init.
> > 
> > This does not resolve the scenario :
> > 1. Disable the "Show Null Array Entries" from Variable view.
> > 2. Debug the program, filter works fine.
> > 3. Exit and Restart.
> > 4. Debug the program, Null Values are not displayed( that's what is store in
> > the pref) but Variable View shows that "Show Null Array Entries" Option is
> > enabled (As we are setting that as true in the start)
> > 
> > to handle this I had added the pref store updation in JavaDebugOptionsManager
> 
> Yes, I see this too, but it seems only if the variables view is not the top
> view in its stack:
> 
> 1. do steps 1, 2 mentioned above
> 2. make the var view not the top view in its stack
> 3. exit / restart
> 4. re-debug, menu item is checked when you bring the var view into focus.
> 
> Oddly enough at step 4 it looks up the correct pref, sets the action state
> to false (unchecked), but it still shows up as checked.

Yes, I had explained in Comment #8 and #9. Problem happens when Variable view is in the top. The initialization is not happening (May be we need to create a bug ?)
Comment 17 Sarika Sinha CLA 2014-05-13 05:34:35 EDT
Created attachment 243005 [details]
Workaround patch to sync action and Preference in Variables and Expression View
Comment 18 Sarika Sinha CLA 2014-05-13 06:04:23 EDT
(In reply to Curtis Windatt from comment #15)
> Using Sarika's patch, I still see one issue:
> 1) Have expressions view open with 'show null entries' unchecked
> 2) Restart Eclipse
> 3) Open expression view menu, 'show null entries' is checked!
> 
> When I launch the example program and inspect an item, null entries are
> shown in the popup.
> If I use Ctrl-Shift-I to move the inspect to the expressions view, null
> entries are NOT shown and the menu item is correctly set unchecked.
> 
> I expected the change to the plugin.xml extension would have avoided this.
> You can also reproduce in a new workspace, just opening the expressions
> view.  Perhaps the menu doesn't differentiate between what view it is in
> until content is added to the view and the filter applied?

Few points :
1. On Start/ Restart Variables /Expresison view "Show Null Array Values" will always get defaulted to true but it will be in sync with preference and values displayed as explained in comment # 9
2. I had defaulted Preference value for Expression view  as false as all the values in Expression view were defaulted to false, I have changed it now to true.
Comment 19 Dani Megert CLA 2014-05-13 06:24:32 EDT
Sorry for not chiming in earlier. Assuming comment 9 is correct and it is indeed a bug in the compatibility layer (didn't check), then this should be moved to Platform UI, best with a small demo plug-in, and fixed there.

I would not release the proposed workaround at this point (RC1).
Comment 20 Dani Megert CLA 2015-02-06 08:36:53 EST
(In reply to Curtis Windatt from comment #4)
> +1 works great, remembers the setting correctly after restart.
> 
> http://git.eclipse.org/c/jdt/eclipse.jdt.debug.git/commit/?id=6b0aee2c137a32718e015329035672c62a1e1751
> 

Not really great. Now, out of the box null values aren't show anymore. I've reverted that code again.

The initial state of the menu is taken from XML (currently 'false'). We could set this to 'true', but again, this would not match if the user previously unchecked the action. For that to work we'd have to fix bug 2897.


Possible fixes are:

1) To get the right state the platform could load all plug-ins that contribute an action to the view. This would mean that even if that action is never used, or the view populated, we'd load the plug-ins. This is a no go.

2) We replace the Java > sub-menu with a dialog that allows to set the filters. If we load the dialog we also know the correct state of each filter.

3) We move the filters to a preference page and replace the Java > sub-menu with an action that opens that preference page.

I think for now I'd leave this bug as is. If we want to fix it I'd go with 2).
Comment 21 Sarika Sinha CLA 2015-02-10 06:19:07 EST
Moving this out of 4.5
Comment 22 Eclipse Genie CLA 2020-02-24 17:55:50 EST
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. As such, we're closing this bug.

If you have further information on the current state of the bug, please add it and reopen this bug. 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.