Use the FindBugs-IDEA plugin to find potential bugs in your code

http://blog.csdn.net/fancy_xty/article/details/51718687

We usually find various errors after the APP goes online, especially the null pointer exception. These errors are very bad for the user experience, but In fact, most of the problems can be found in advance.

In the process of writing code, we may not always remember to check for empty references, and delete unused variables, which may be difficult to find during our own testing. The problem, once the app goes online and the user's usage environment changes, these potential problems may appear.
Of course, this is only for a novice like me who often writes null pointer exceptions, the programming style is good, and the programming is rigorous Please ignore the great god.

Today I introduce a small plug-in to help us find these potential problems in advance, and then modify them as needed. The

first step is to download the plug-in and search for FindBugs in File->Setting->Plugins->Browser Repositorise in AndroidStudio -IDEA. Then install.
install-plugin
Because the plug-in has been installed, the install button has disappeared.
After the installation is successful, you need to restart AS before you can use it.
use-plugin
waits quietly for a while, and generates the analysis result below. Write the picture

here Description There are too many bugs

found , and the number will not be displayed.
Let me briefly introduce these types of bugs, of course some of them can be ignored.
1->Bad pratice bad habit of programming
It is mainly a naming problem. For example, class names should start with uppercase, and strings should not be compared using equals and unequals. There may be exceptions. It is best to use try-catch to wrap the code. The method has a return value but is ignored, etc. These if If you don’t want to change it, you can just ignore it.

2->Malicious code vulnerability
Sounds scary, mainly because some properties are directly obtained by using public to other classes. It is recommended to change to private and provide get/set methods for them.
Also Some public static fields may be acquired by other packages.
These also need to be based on the specific situation of the project. Personal opinion. In some unimportant classes, sometimes it may be more convenient to use properties directly. If you think These do not need to be modified and can be completely ignored.

3->Dodgy code Bad code
such as a double/float being coerced to int/long may lead to loss of precision, some floating point numbers close to zero will be directly truncated, in fact we It should be reserved.
By the way, I have read the "App Development Record" in the past two days. I have also gained some gains in standardizing the code and avoiding errors as much as possible.
When type conversion, we should provide a safe conversion for type conversion. method, because we will never know what will happen to our app in the hands of the user, so we have to reduce the possibility of this error as much as possible.

For example, when using switch, no default is provided.

The redundant null check is the value that cannot be null, and the non-null judgment is added, which is unnecessary. Belong to code redundancy

· unsafe type conversion and so on.
There are too many to list here.

4->performance performance
is mainly some useless code, such as declaring unused attributes, etc.

5->correctness The correctness of the code should be considered the most important,
mainly because there is no non-null determination of variables, and null pointer exceptions may occur in special cases.

This article is only about the main function of the FindBugs plugin. Introduce, I believe you can find more usage of this tool in the process of use.

This blog was originally created by the blogger, please declare the source for reprint
http://blog.csdn.net/fancy_xty/article/details/51718687

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565022&siteId=291194637