EVALUATION
after evaluatio I've came to the followin way to change the code to postpone
the initialization:
1. I've changed DropTarget to initialize flavorMap field in ctor, since
otherwise we could initialize it (as inline initializer) and then
rewrite it in ctor.
2. I've decided to not postpone initialization of flavorMap field (as
Igor suggested) since getDefaultFlavorMap() uses context class loader of
the current thread, thus calling the same method from another thread may
have different result. So, theoretically, such change may cause
regression if someone uses this particular aspect of the current
behavior. Instead of postponing initialization of flavorMap, I've
decided to make SystemFlavorMap lazily initialized.
For this reason I've extracted all code we had in ctor of this class to
new method initSystemFlaforMap(). And since it initializes two fields:
flavorToNative and nativeToFlavor, I've changed code to not access these
fields directly, but use accessors instead and these accessors call
initSystemFlavorMap() if needed.
|
SUGGESTED FIX
*** DropTarget.java Tue Sep 4 21:37:42 2007
--- DropTarget.java.fix Tue Sep 11 16:07:39 2007
***************
*** 460,466 ****
* @return the FlavorMap for this DropTarget
*/
! public FlavorMap getFlavorMap() { return flavorMap; }
/**
* Sets the <code>FlavorMap</code> associated
--- 460,470 ----
* @return the FlavorMap for this DropTarget
*/
! public FlavorMap getFlavorMap() {
! if (flavorMap == null)
! flavorMap = SystemFlavorMap.getDefaultFlavorMap();
! return flavorMap;
! }
/**
* Sets the <code>FlavorMap</code> associated
***************
*** 851,855 ****
* The FlavorMap
*/
! private transient FlavorMap flavorMap = SystemFlavorMap.getDefaultFlavorMap();
}
--- 855,859 ----
* The FlavorMap
*/
! private transient FlavorMap flavorMap;
}
|