Overview
The result file for the BEAM report is defined by the--beam::complaint_file in Build.xml, where this is assumed to be beam-messages. Beam-messages records all of the Code defects reported, these defects are divided into Error,mistake and WARNING three categories, the severity of descending. Each specific error, mistake, and WARNING represent a bug pattern, and this article then understands some of these important error patterns through an instance analysis, telling readers how to avoid these error patterns when writing Java code, thus writing high quality code.
Due to space reasons, this article mainly focuses on four common error patterns, and at the end of a brief introduction to the programming should also pay attention to some other skills, the article structure is as follows:
Manipulating empty objects
Array access bounds
Except for the 0 error
Memory leaks
Other Tips
Manipulating empty objects
This is the quoted ERROR2 error mode. According to personal project experience, this error pattern appears most frequently, but programmers are often difficult to find, because the compiler can not find errors may be in the code for a long time will not occur, but once it appears, the program will terminate the operation and throw runtime exception Java.lang.NullPointerException. This usually occurs when the Null object error mode is manipulated.
Method of calling empty object
To access or modify a domain for an empty object
To access or modify an array element of an empty array object
Synchronizing Empty objects
Incoming NULL object parameters
Let's introduce them in simple and understandable examples.
Method of calling empty object
Listing 1. Invoke the CharAt () method of an empty String object
String str = null;
int a = 0;
if( a > 0 ) {
str = new String[]{ "developer " , "Works"};
}
char ch = str.charAt(0);
This is the most typical example of calling an empty object method, calling an uninitialized String object's Chatat () method.