Eclipse Plug-in Development FindBugs Plugin

Source: Internet
Author: User
Tags code tag manual modify net string window
   questions raised:

When we finish writing the code, after the unit test and other tests to submit the formal operation, can only be run by the system to detect the problem of our code, the code hidden in the process of running the system was found, and then to make the corresponding changes, then the cost of late changes is quite high.

Workaround:

Now there are a lot of Java code Analysis tools, findbugs in the Open source project, which can help you find some of the hidden errors in the code, improve your code capabilities and system security and reliability.

   installation

jdk:1.5.0 from http://java.sun.comGo up and download the installation

eclipse:3.1.1 from http://www.eclipse.orgGo up and download the decompression

findbugs:0.9.4 from http://findbugs.sourceforge.net/

The Official document http://findbugs.sourceforge.net/manual/

Eclipse plugin for FindBugs version 0.0.17 from http://findbugs.sourceforge.net/downloads.htmlDownload

   Plug-in Management tips

Hint: the newly downloaded plugin plugin must not be placed in the original Eclipse directory.
  1. The premise is that you have installed the Eclipse tools, such as installed in the E:\OpenSource\Eclipse\ directory, the following directory to%eclipse_home%;
  2. At this time the default plug-in is in the%eclipse_home%\plugins directory;
  3. To establish a pluginsnew directory under%eclipse_home%;
    For example: E:\OpenSource\Eclipse\PlugInsNew\
  4. You have downloaded a new plugin, such as: XYZ
    Then create the XYZ directory in the%eclipse_home%\pluginsnew\ directory, which is the Eclipse directory, and the Eclipse directory contains features and plugins two subdirectories, as shown in the following figure:

      
  5. Put the downloaded new plugin file in the appropriate directory below
    %eclipse_home%\pluginsnew\xyz\eclipse\features
    %eclipse_home%\pluginsnew\ Xyz\eclipse\plugins
  6. Create a file of related. Link
    Then create a xyz.link file in the%eclipse_home%\links directory.
    Content as follows: Path=e:/opensource/eclipse/pluginsnew/xyz on a line of such path instructions only.
    Of course, the use of relative path to express may be more intuitive, easy to file the whole movement and the group of all members of the sharing of naming, save the move to change the link file in the absolute path and painstaking effort. Direct copies of the past can be used.
    That is, the contents of the Xyz.link file are: path=. /pluginsnew/xyz
    In this way, if you download a number of plug-ins can be done to create a number of link files, want to load which plug-ins to put the plug-in link file to the%eclipse_home%\links directory can be, use and management are very convenient, it is recommended not to put in the default installation directory;
    If your%eclipse_home% is different, please change the path in the Xyz.link file
  7. Delete, close eclipse
    deleting%eclipse_home%\links\xyz.link files can
    Delete%eclipse_home%\pluginsnew\xyz Entire directory and file
  8. You can restart Eclipse


After using

To restart Eclipse, you can see the "FindBugs Project" => Plug-in details in Help => about Eclipse SDK FINDB UGS Plug-in version 0.0.17 plug-in, as shown in the following illustration:



findbugs usage

FindBugs is a program that can find bugs in Java programs.

It is designed to look for code that is in the Bug Patterns list. The

Bug patterns refers to an instance of a code that is likely to be wrong. The

is currently findbugs the highest version of 0.9.4, but the update is fast and you should always go up and see if there are any new releases. Eclipse plugin for findbugs highest version 0.0.17.

System requirements

Use findbugs for at least JDK1.4.0 versions, FindBugs is platform independent and can run on platforms such as Gnu/linux, Windows, MacOS X, and so on.

Running findbugs requires at least 256 MB of memory, and if you are analyzing a large project, you need more memory.  

FindBugs The detailed operations that are run independently and combined with ant are not covered, you can see the official document http://findbugs.sourceforge.net/manual/

The effect of running independently is as follows:



This article mainly describes what is used in eclipse

Open the Bug Details view

Windows => show View => ... => FindBugs => bugdetails

  

In Package Explorer or Navigator view, select your Java project, right-click, and see the Find Bugs menu item with "Find Bugs" and "clear Bug markers" in the submenu, as shown in the following illustration:

  

We build a simple test file Test.java content as follows:


We dot "Find Bugs", the runtime will appear as the following progress box:

After the run is over, you can see in problems the following warning message content added

FindBugs The post-run warning message content is displayed not only in the problems view, but also in the Source Code tag box, in the source editor we can see the warning ID, as shown in the following figure:

When the cursor points to the code of your warning message, there is a corresponding error message, similar to the error or warning message hint for eclipse itself.

Select the corresponding problem in the problems view, you will be in the code Editor to switch to the appropriate code to facilitate the corresponding information to the appropriate code changes.

  

In the problems view, select the appropriate question entry, right button, in the pop-up menu, you can see "Show Bug Details", as shown in the following figure:

  

Point, it will switch to the bug details view to display more detailed hints.

Of course, in the Code editing window, when you click on an icon with a warning message, you automatically switch to the Bud Details window to see the detailed warning, as shown in the following figure.

  

According to the detailed information here, you can get the findbugs why the warning message to your code, and the corresponding processing methods, according to its prompt, you can quickly and easily modify the code.

  

According to the prompts, we will modify the code as follows, and then run will not be reported a warning message.


public class Test {
private string[] name: 
public string[] GetName () {
     string[] temp = name; 
return temp.
} 
public Voi D setname (string[] name) {     


  Configure FindBugs

Select your project, right key => Properties => FindBugs =>

  

The information that can be configured includes the relevant settings for the four options shown in the previous illustration:


  1. Run FindBugs automatically switch

    When this item is selected, FindBugs will automatically run when you modify the Java class, such as when you set up the Eclipse automatic compiler switch, and when you have finished modifying the Java file Save, FindBugs will run and display the corresponding information.

    When this item is not selected, you can only run findbugs to check your code each time you need it.

  2. Minimum priority to the Select item

    The option is to choose which level of information you want to display, with low, Medium, and high three options to choose from, much like the log4j level setting. Like what:

    You select the High Select item, then only the high level of the cue message will be displayed.

    You select the Medium option, then only the medium and high level prompts will be displayed.

    If you select the low selection, all levels of the prompts will be displayed.

  3. Enable Bug Categories Selection

    Here are some options for displaying bug classifications:

    Correctness relevant aspects of code correctness

    Performance about code performance related Aspects of

    Internationalization about code internationalization related aspects of

    Multithreaded correctness related Aspects of code multithreading correctness

    Style about code style related aspects of

    Malicious code vulnerability Related aspects of malicious vandalism

    For example, if you remove the Style check box from the selection, the warning message associated with the style category will not be displayed. Others are similar.

  4. Select bug patterns to check for selection

    Here you can select the related bug pattern entry you want to check

    You can see from the bug codes, detector name, detector description which aspects of the content you want to check, you can select or remove the appropriate check conditions as needed.


  Summarize

This plugin is a good feature that can help us improve the ability to write Java code and write more secure and reliable code. It is recommended to use or add to ant for continuous construction.

Now you can come up with a project you've developed and check your code for any problems.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.