Unidata/IDV — pull request #77 by tommyjasmin (2014-05-09 03:29:27+00:00)
Title: Prevent NPEs when changing units on cross sections [1560]

Hi guys - First let me explain how to demonstrate the problem in IDV here:

1. Load any grid. Ex: NCEP GFS CONUS 80, single time step is fine.
2. Display a 3D parameter as a Vertical Cross Section.
3. In the Layer Controls, Edit -> Change Display Unit
4. You'll get a Null Pointer Exception

This one is a little convoluted. The above sequence invokes applyProperties()
in the CrossSectionViewManager, which assumes components associated with
the Properties dialog have been instantiated. But by going this route, they haven't
been yet. If you had done Edit -> Properties first, everything would have been fine.

Why can't we just make sure the components exist when units are changed?
Because ViewManager re-creates them every time the dialog is shown (see
getPropertiesComponent() in ViewManager.java). There are I'm sure other
ways to resolve this but may require significant coding in ViewManager. So
I just created a boolean flag in the CrossSectionViewManager subclass.
If this flag has not been set yet, skip the general properties updates, since
those components don't exist yet.

Interesting there already is a "propertiesDialogShown" boolean flag in ViewManager,
but it gets reset false every time the properties dialog goes away, so is
apparently only supposed to indicate the dialog is currently active.

We've beat on this one pretty good, and if we missed anything, you know Bob
will find it ;-)