<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    rosial

    lost memory
    數(shù)據(jù)加載中……

    Violations(多數(shù)內(nèi)容來(lái)自他人blog與論壇討論)

    Critical!


    1. Findbugs——Dodgy - Dead store to local variable
     
    例如:String abc = "abc";
          String xyz = new String();
          xyz = abc;
    編譯肯定通過(guò),運(yùn)行也不會(huì)出問(wèn)題。   

    來(lái)分析一下這個(gè)語(yǔ)句:String xyz = new String();   
    這一句執(zhí)行3個(gè)動(dòng)作:   
    1)創(chuàng)建一個(gè)引用xyz   
    2)創(chuàng)建一個(gè)String對(duì)象   
    3)把String的引用賦值給xyz

    其中,后面兩個(gè)動(dòng)作是多余的,因?yàn)楹竺娴某绦蛑心銢](méi)有使用這個(gè)新建的String對(duì)象,而是重新給xyz賦值。   
              xyz = abc; 

    所以,只需要   
              String xyz = abc; 就可以完成整個(gè)操作了,可以把上面的語(yǔ)句修改為:
       String abc = "abc";
              xyz = abc;
    這樣,findbugs就不會(huì)報(bào)了。

    FindBugs的提示:Dead   store   to   local   variable。   
    意思應(yīng)該是:本地變量存儲(chǔ)了閑置不用的對(duì)象,也就是說(shuō)這個(gè)變量是多余的。
    FindBugs的提示:Dead   store   to   local   variable。 
    意思應(yīng)該是:本地變量存儲(chǔ)了閑置不用的對(duì)象。 

    zbo(大門(mén))說(shuō)的IDEA中的提示比較直觀。 
    'new   Object() '是多余的。 ——Variable   'aObject '   initializer   'new   Object() '   is   redundant.  

    ----------------------------------------------------------------------------------------------------------------

    [hyddd的FindBugs分析記錄](méi)[M D DLS] Dead store to local variable

    [M D DLS] Dead store to local variable [DLS_DEAD_LOCAL_STORE]

    This instruction assigns a value to a local variable, but the value is not read or used in any subsequent instruction. Often, this indicates an error, because the value computed is never used.

    Note that Sun's javac compiler often generates dead stores for final local variables. Because FindBugs is a bytecode-based tool, there is no easy way to eliminate these false positives.

     

    看下面代碼:

    public static void main(String args[]) throws Exception{
        Object str 
    = new Object() ;  //報(bào)錯(cuò)處
        str 
    = new Object() ;
        System.out.println(str);
    }

     

    Object str = new Object();是無(wú)用的代碼,因?yàn)樵谙旅嬗幸痪鋝tr= new Object();,很多語(yǔ)言編譯器它都會(huì)做優(yōu)化,比如:去除一些無(wú)用的代碼以提高效率。JAVA編譯器也會(huì)做一些優(yōu)化,但是,Java編譯器對(duì)上面這段代碼卻沒(méi)有做優(yōu)化(你可以DComplie確認(rèn)一下),編譯后的.class文件還是new了兩次,具體什么原因?qū)е滤蝗プ?/span>這個(gè)優(yōu)化我還不能確定,我覺(jué)得難做這種優(yōu)化不是借口,起碼不應(yīng)該是Sun的借口。

    修改這段代碼方法很簡(jiǎn)單,隨便去掉一行new Object();就可以了。


    這里我遇到了這樣的問(wèn)題:

     1       Class[] paramArray = null;
     2       Object[] objArray = null
     3       String finalRetrun = null;
     4 String[] params = null;
     5       if ((param == null && paramType != null)
     6           || (param != null && paramType == null)) {
     7         out.println("Parameters are not match with parameter types!");
     8       }
     9 
    10       if (param != null && paramType != null) {
    11         params = param.split(";");
    12         String[] paramTypeArray = paramType.split(";");
    13         Object[] paramWithClass = classCast(params, paramTypeArray);
    14         if (null != customMethod) {
    15           paramArray = new Class[] { String.class, String.class, Object[].class };
    16           objArray = new Object[] { entityName, customMethod, paramWithClass };
    17         } else {
    18           paramArray = new Class[] { String.class, Object[].class };
    19           objArray = new Object[] { entityName, paramWithClass };
    20         }

    1-4行中只提示第4行的
    params是dead store,前面3個(gè)不也是有null的無(wú)辜存在嗎?
    反復(fù)看了覺(jué)得差別是params在下面只被重復(fù)賦值一次,而前面3個(gè)變量被重復(fù)賦值多次……不知是不是這樣的原因……



    [hyddd的FindBugs分析記錄](méi)[M S XSS] Servlet reflected cross site scripting vulnerability

    [M S XSS] Servlet reflected cross site scripting vulnerability [XSS_REQUEST_PARAMETER_TO_SERVLET_WRITER]

    This code directly writes an HTTP parameter to Servlet output, which allows for a reflected cross site scripting vulnerability. Seehttp://en.wikipedia.org/wiki/Cross-site_scripting for more information.

    FindBugs looks only for the most blatant, obvious cases of cross site scripting. If FindBugs found any, you almost certainly have more cross site scripting vulnerabilities that FindBugs doesn't report. If you are concerned about cross site scripting, you should seriously consider using a commercial static analysis or pen-testing tool.

     

    先看下面代碼:

    public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
      //
      String v = request.getParameter("v");
      //
      PrintWriter out = response.getWriter();
      out.print(
    "協(xié)議版本號(hào)不對(duì),v="+v);
      out.close();
      //
    }
    這里字符串v沒(méi)有作過(guò)濾,直接返回給用戶(hù),有可能操作XSS攻擊。具體關(guān)于XSS攻擊的資料,可以參考上面Findbugs說(shuō)明中的連接,這里就不多說(shuō)了。


    2. method invokes inefficient new String() constructor.
    (方法中調(diào)用了低效的new String()構(gòu)造方法)
    例如: String abc = new String("abc");
    這個(gè)語(yǔ)句會(huì)去調(diào)用String的構(gòu)造方法String(String)在堆棧創(chuàng)建一個(gè)對(duì)象,并把這個(gè)對(duì)象的引用賦給abc.
    如果直接采用String abc = "abc";的方式就不用在堆棧中新創(chuàng)建一個(gè)對(duì)象了,而直接在值棧中創(chuàng)建一個(gè)"abc"對(duì)象,把"abc"賦給變量abc

    所以,在沒(méi)有特殊需要的時(shí)候就不要去創(chuàng)建新的對(duì)象,盡量在值棧中尋找需要的內(nèi)容。比如,在一個(gè)方法返回值為"abc"時(shí),不要采用return new String("abc");的方法,而改變?yōu)槭褂胷eturn "abc";的方法,提高執(zhí)行效率。
      

    3. XXX mail fail to close stream.
    (輸入)流可能沒(méi)有關(guān)閉。

    在進(jìn)行文件流的操作時(shí),沒(méi)有對(duì)輸入輸出流進(jìn)行關(guān)閉,或者關(guān)閉過(guò)程可能出錯(cuò),就會(huì)報(bào)這個(gè)bug。最好是在finally中將所有的輸入輸出流關(guān)閉。

    4. Possible null pointer dereference in method on exception.
    (在有異常的情況下,可能調(diào)用的引用是一個(gè)空指針)

    這個(gè)很容易理解,比如在try塊中對(duì)一個(gè)空引用的變量進(jìn)行賦值,而在try塊之后才引用這個(gè)變量,就可能會(huì)出現(xiàn)空指針異常。

    5.Suspicious reference comparison.
    (懷疑對(duì)兩個(gè)引用進(jìn)行比較)

    在對(duì)兩個(gè)對(duì)象(即兩個(gè)引用)進(jìn)行比較的時(shí)候,使用的不是equals()方法,而采用==的方式進(jìn)行,可能會(huì)出現(xiàn)結(jié)果與預(yù)期不一致的情況.
    當(dāng)然,在對(duì)兩個(gè)引用進(jìn)行equals()的時(shí)候,對(duì)象是需要重寫(xiě)hashcode()方法的。


    以上來(lái)自:



    3. Performance - Method concatenates strings using + in a loop

    Plugin: findbugs    Key: SBSC_USE_STRINGBUFFER_CONCATENATION

    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.

    For example:


     // This is bad
      String s = "";
      
    for (int i = 0; i < field.length; ++i) {
        s 
    = s + field[i];
      }

      
    // This is better
      StringBuffer buf = new StringBuffer();
      
    for (int i = 0; i < field.length; ++i) {
        buf.append(field[i]);
      }
      String s 
    = buf.toString();


    4. Bad practice - Method may fail to close stream on exception

    Plugin: findbugs    Key: OS_OPEN_STREAM_EXCEPTION_PATH

    The method creates an IO stream object, does not assign it to any fields, pass it to other methods, or return it, and does not appear to close it on all possible exception paths out of the method.  This may result in a file descriptor leak.  It is generally a good idea to use a finally block to ensure that streams are closed.




    Just delete it!!



    posted on 2012-02-27 18:43 rosial 閱讀(1328) 評(píng)論(0)  編輯  收藏


    只有注冊(cè)用戶(hù)登錄后才能發(fā)表評(píng)論。


    網(wǎng)站導(dǎo)航:
     
    主站蜘蛛池模板: 亚洲香蕉免费有线视频| 国产美女亚洲精品久久久综合| 久久91亚洲精品中文字幕| 青青草97国产精品免费观看| 午夜一级毛片免费视频| 亚洲综合无码一区二区痴汉| 色妞WWW精品免费视频| 亚洲天堂免费在线| 久久不见久久见免费影院| 亚洲一区在线观看视频| 四虎国产精品免费久久| 亚洲日本中文字幕天天更新| 大学生高清一级毛片免费| mm1313亚洲国产精品无码试看 | 日本免费在线中文字幕| 香蕉蕉亚亚洲aav综合| 99在线观看视频免费| 亚洲制服丝袜精品久久| 麻豆国产VA免费精品高清在线| 亚洲JLZZJLZZ少妇| 精品国产亚洲一区二区在线观看 | 免费国产在线视频| 亚洲第一成年网站大全亚洲| 性短视频在线观看免费不卡流畅 | 免费在线观看亚洲| 不卡精品国产_亚洲人成在线| 在线涩涩免费观看国产精品 | 亚洲成av人片不卡无码久久| 色爽黄1000部免费软件下载| 亚洲欧洲无码AV电影在线观看 | 一级一级毛片免费播放| 国产成人A人亚洲精品无码| 久久久免费精品re6| 亚洲中文字幕无码av| 国产精品亚洲精品日韩已方| 十八禁无码免费网站| 亚洲hairy多毛pics大全| 久久久久一级精品亚洲国产成人综合AV区 | 亚洲日本视频在线观看| 日韩高清免费观看| 成全视频高清免费观看电视剧|