Bug: Load of known null value
Pattern id: NP_LOAD_OF_KNOWN_NULL_VALUE, type: NP, category: STYLE
The variable referenced at this point is known to be null due to an earlier check against null. Although this is valid, it might be a mistake (perhaps you intended to refer to a different variable, or perhaps the earlier check to see if the variable is null should have been a check to see if it was nonnull).
½âÊÍ£º
NodeΪnull£¬»¹½øÒ»²½µ÷ÓÃËüÉÏÃæµÄ·½·¨£¬³ý·ÇÄãÄܱ£Ö¤µ±nodeΪnullµÄʱºò
isDeleteSingleObjectΪfalse£¬·ñÔòºÜ¿ÉÄÜ·¢Éú¿ÕÖ¸ÕëÒì³££¬ÎÒ¹À¼Æ×÷ÕßÊǵڶþ¸öifÊÇÏëÅÐ¶Ï node != null°É¡£ ½â¾ö·½·¨£º
ŬÁ¦ÕÒµ½Ô×÷Õߣ¬µ±ÃæÑ¯ÎÊÆäÓÃÒâ¡£
44. EI_EXPOSE_REP2
°¸Àý DOÀà
Bug: SingleNePollConfigDialog.collectValues(Hashtable) may expose internal representation by storing an externally mutable object into SingleNePollConfigDialog.values Pattern id: EI_EXPOSE_REP2, type: EI2, category: MALICIOUS_CODE
½âÊÍ£º
²ÎÊývalues±£´æÔÚµ±Ç°Ï̵߳ÄÖ´ÐÐÕ»ÖУ¬¶øthis.values±£´æÔÚ¶ÑÉÏ£¬ËüÃÇͬʱָÏòͬһ¸ö¶Ô Ï󣬶ԲÎÊývaluesµÄÈκβÙ×÷¶¼»áÓ°Ïìµ½this.values£¬Èç¹ûÄãÖªµÀÕâÒ»µã£¬¶øÇÒ±¾Òâ¾ÍÊÇÕâ ÑùµÄ£¬ÄÇôÄã¿ÉÒÔºöÂÔÉÏÃæÕâЩ»°£¬µ«ÊÇÏÂÃæÕâЩ»°ÄãÓ¦¸ÃºÃºÃÌýÌý¡£
ÕâÊÇÒ»¶ÎÕýÈ·µÄ´úÂ룬µ«²»ÊÇÒ»¶Î¿Éά»¤ÐÔÇ¿¡¢¿ÉÀí½âÐÔÇ¿µÄ´úÂ룬²ÎÊý´ú±í²Ù×÷µÄÌõ¼þ£¬ ËüÃÇÓ¦¸ÃÊÇÖ»¶ÁµÄ£¬ÎÒÃDz»Ó¦¸Ã¶ÔËüÖ±½Ó½øÐвÙ×÷»òÕ߸³Öµ¡£ ½â¾ö·½·¨£º
Èç¹û°ÑÉÏÃæ¶Ô²ÎÊývaluesµÄ²Ù×÷¶¼¸Ä³Éthis.values£¬ÎÒÏàÐÅÄãºÍÄãµÄͬʶ¼»á¾õµÃÕâÑùµÄ´ú Âë¸ü¼ÓÇåÎú¡£
}
°¸Àý¶þ DOÀà
Bug: SingleNePollConfigDialog.collectValues(Hashtable) may expose internal representation by storing an externally mutable object into SingleNePollConfigDialog.values Pattern id: EI_EXPOSE_REP2, type: EI2, category: MALICIOUS_CODE
This code stores a reference to an externally mutable object into the internal representation of the object. If instances are accessed by untrusted code, and unchecked changes to the mutable object would
compromise security or other important properties, you will need to do something different. Storing a copy of the object is better approach in many situations.
·ÒëÔ¸Ò⣺
´Ë´úÂë´æ´¢µ½Ò»¸öµ½¶ÔÏóµÄÄÚ²¿±íʾÍⲿ¿É±ä¶ÔÏóµÄÒýÓá£Èç¹ûʵÀýÊÇÓɲ»ÊÜÐÅÈεĴúÂ룬 ²¢ÒԿɱä¶ÔÏó»áΣ¼°°²È«»òÆäËûÖØÒªµÄÊôÐÔÑ¡Öиü¸Ä·ÃÎÊ£¬ÄãÐèÒª×ö²»Í¬µÄ¶«Î÷¡£´æ´¢Ò»¸ö ¶ÔÏóµÄ¸±±¾£¬ÔÚÐí¶àÇé¿öÏÂÊǸüºÃµÄ°ì·¨¡£
½âÊÍ£º
DOÀàʵÀý²úÉúÖ®ºó£¬ÀïÃæ°üº¬µÄDate²»ÊÇÔʼÊý¾ÝÀàÐÍ£¬µ¼ÖÂÆägmtCrateÊôÐÔ²»¹âÊÇ
set·½·¨¿ÉÒԸıäÆäÖµ£¬ÍⲿÒýÓÃÐÞ¸ÄÖ®ºóÒ²¿ÉÄܵ¼ÖÂgmtCreate ±»¸Ä±ä£¬»áÒýÆð¿ÉÄܵIJ» °²È«»òÕß´íÎó¡£
Õâ¸öÊÇÒ»¸ö²»ºÃµÄʵ¼ù£¬²»¹ýÎÒÃÇÓ¦ÓÃÀïÃæDO¶¼ÊDZȽϼòµ¥Ê¹Ó㬲»Ì«»á³öÏÖÕâÖÖÇé¿ö¡£
½â¾ö·½·¨£º
Ð޸ijɣº
public Date getGmtCreate() {
return new Date(this.gmtCreate.getTime()); //ÕýÈ·Öµ }
45. EI_EXPOSE_REP
Bug: temsLoader.getItemsWithPriority() may expose internal representation by returning ItemsLoader.m_htItemsWithPriority
Pattern id: EI_EXPOSE_REP, type: EI, category: MALICIOUS_CODE ½âÊÍ£º
¸Õ¿ªÊ¼Ò»¿´Í¦ÄÉÃÆµÄ£¬Õâ¸ö·½·¨ÓÐʲôÎÊÌâÂ𣿺óÀ´×Ðϸ¿´Ò»Ï£¬·¢ÏÖ·µ»ØÖµ¶¼ÓÐÒ»¸öÌØµã£¬ ËüÃǶ¼ÊǼ¯ºÏÊý×éÖ®ÀàµÄ£¬ÎÒÏëfindBugsµÄ±¾ÒâÊÇ£¬Ä³Ð©Êý¾Ý¼¯ºÏ²»Ó¦¸ÃÖ±½Ó¶ÔÍâÌṩpublic ·µ»Ø·½·¨£¬¼´Ê¹±íÃæÉÏÌṩÁËget·½·¨£¬µ«Êµ¼ÊÉÏ¿ÉÒÔÈÎÒâÐÞ¸ÄÀïÃæµÄÊý¾Ý¡£ ½â¾ö·½·¨£º
Èç¹ûÄãÈ·¶¨ÕâЩÊý¾Ý¼¯ºÏ²»Ó¦¸Ã±»Íâ½çÐ޸ģ¬ÄÇô¶ÔÓÚ»ù±¾Êý¾ÝÀàÐÍ£¬ÄãÌṩget·½·¨¼´¿É£¬ ¶ÔÓÚÒýÓã¬get·½·¨ÀïµÄ·µ»ØÖµÓ¦¸ÃÊÇÊý¾ÝµÄ¿½±´¡£
46. NP_NULL_PARAM_DEREF
Bug: Method call passes null for nonnull parameter of queryScriptData(ObjService) Pattern id: NP_NULL_PARAM_DEREF, type: NP, category: CORRECTNESS ½âÊÍ£º
µ±getAllListFiles·½·¨·¢ÉúÁËÈκÎÒì³££¨checkedºÍunchecked£©£¬allFiles¶¼Îªnull£¬¹Ø¼üÊÇÔÚ queryScriptData·½·¨À²¢Ã»ÓжԲÎÊýÊÇ·ñΪnull½øÐÐÅжϣ¬ËüÖ±½Óµ÷ÓÃÁ˲ÎÊý¶ÔÏóÉÏÃæµÄ ·½·¨£¬Õâ¿Ï¶¨»á·¢Éú¿ÕÖ¸ÕëÒì³£¡£
Ò»¸öÓÅÐãµÄ³ÌÐòÔ±£¬ÔÚ¹ýÂí·ʱ¶¼ÒªÏòÁ½±ß¿´Ò»Ï£¬ÔÚдһ¸ö·½·¨Ê±£¬Ê×ÏÈÒª¿¼ÂǵľÍÊÇ¶Ô ·½·¨²ÎÊýµÄÓÐЧÐÔÅжϡ£ ½â¾ö·½·¨£º
ÔÚqueryScriptData·½·¨Àï¶Ô²ÎÊý½øÐÐÓÐЧÐÔÅжϡ£
46. SBSC_USE_STRINGBUFFER_CONCATENATION
Bug: Method InitDBPoolParaTask.execute() concatenates strings using + in a loop Pattern id: SBSC_USE_STRINGBUFFER_CONCATENATION, type: SBSC, category: PERFORMANCE
The method seems to be building a String using concatenation in a loop. In each iteration, the String is converted to a
StringBuffer/StringBuilder, appended to, and converted back to a String. This can lead to a cost quadratic in the number of iterations, as the growing string is recopied in each iteration.
Better performance can be obtained by using a StringBuffer (or StringBuilder in Java 1.5) explicitly.
½âÊÍ£º
ÿ´ÎÑ»·ÀïµÄ×Ö·û´®+Á¬½Ó£¬¶¼»áвúÉúÒ»¸östring¶ÔÏó£¬ÔÚjavaÖУ¬Ð½¨Ò»¸ö¶ÔÏóµÄ´ú¼Û ÊǺܰº¹óµÄ£¬ÌرðÊÇÔÚÑ»·Óï¾äÖУ¬Ð§Âʽϵ͡£ ½â¾ö·½·¨£º
ÀûÓÃStringBuffer»òÕßStringBuilderÖØÓöÔÏó¡£
Ïà¹ØÍÆ¼ö£º