Optimizing Java code with IBM static tools, part 2nd: Parsing Error Reporting

Source: Internet
Author: User
Tags empty

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.

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.