copy代码(含static对象)留下的致命错误

 转载请注明出处:http://www.cnblogs.com/xunzhaorendaxia/p/8776857.html 

本来以为这个bug快改不好了,然而发现了问题所在
copy代码没有完全改掉对象名称,导致对象重复创建了,由于是static所以debug过程中
注释了addProperty(gridRowDetailKeyProperty)
以及引用gridRowDetailKey ()的方法段;
 
public static PropertyDescription gridRowGroupKey = null;
public static PropertyDescription gridRowGroupKey(){
        if( gridRowGroupKey== null ){
          // propertyDescription 初始化属性分别为:group section key title dataType visible enable editable gridRowGroupKey
= new PropertyDescription (PropGroup.GridRow, null, FormStrDef.D_GridRowGroupKey, StringTable.getString(StringSectionDef.S_Form, FormDef..D_GridRowGroupKey), JavaDataType.USER_STRING, " GridRowType == 'Group', true, true") } return gridRowGroupKey; } public static PropertyDescription gridRowDetailKey = null; public static PropertyDescription gridRowDetailKey (){ if( gridRowGroupKey== null ){ gridRowGroupKey = new PropertyDescription (PropGroup.GridRow, null, FormStrDef.D_GridRowDetailKey, StringTable.getString(StringSectionDef.S_Form, FormDef.D_GridRowDetailKey), JavaDataType.USER_STRING, " GridRowType == 'Fix', true, true") } return gridRoDetailKey; }

 

 
对象还在,由于效果该属性当为分组行的时候出现
解释:第一次没注释前执行了gridRowDetailKey ()静态方法。使得对象gridRowGroupkey对象重新创建,
            注释后debug ,调用方法gridRowGroupkey()返回的对象已经新创建的对象了。
解决问题的心理表征:
        1.debug找到空指针报错出,发现是Decription为空
            猜测与Decription有关
        2.运行app发现当分组行时可见,后又重现一遍发现是固定行可见,猜测之前观测可能是误会属性名称"所属分组标识"&&"所属明细标识"
            猜测与之前copy的GroupKey属性有关系
        事后重现发现虽然注释的属性出现,但之前的所属分组表示属性已经不在;但是在找问题期间没有注意 
心得体会:
        1,少拷代码,尤其是static属性的,可能会导致别的对象和自己的对象都出问题
        2.  不要懒,多bebug去发现问题来源,出现控制针就去添加该对象的方法里加断点调式,如果是static对象更要注意重头开始运行debug
        才能看清对象创建过程。
posted @ 2018-04-10 10:12  寻找任大侠  阅读(257)  评论(0编辑  收藏  举报