Start here

Home
About Klocwork
What's new
Fixed issues
Release notes
Installation

Reference

C/C++ checkers
Java checkers
C# checkers
MISRA C 2004 checkers
MISRA C++ 2008 checkers
MISRA C 2012 checkers
MISRA C 2012 checkers with Amendment 1
Commands
Metrics
Troubleshooting
Reference

Product components

C/C++ Integration build analysis
Java Integration build analysis
Desktop analysis
Refactoring
Klocwork Static Code Analysis
Klocwork Code Review
Structure101
Tuning
Custom checkers

Coding environments

Visual Studio
Eclipse for C/C++
Eclipse for Java
IntelliJ IDEA
Other

Administration

Project configuration
Build configuration
Administration
Analysis performance
Server performance
Security/permissions
Licensing
Klocwork Static Code Analysis Web API
Klocwork Code Review Web API

Community

View help online
Visit RogueWave.com
Klocwork Support
Rogue Wave Videos

Legal

Legal information

NPE.RET

A NullPointerException is thrown in case of an attempt to dereference a null value. The dereference may be a function call, a read or write of a field, or an array access. NPE.RET is reported for the result of a method call being dereferenced when there is a path on which the value coming from a method call returns null.

Example 1

15     Reader getReader(String configurationPath) throws IOException {
16         File file = new File(configurationPath);
17         if (file.exists()) {
18             return new BufferedReader(new FileReader(file));
19         }
20         return null;
21     }
22 
23 
24     Reader getDefaultReader() throws IOException {
25         return getReader("conf");
26     }
27 
28     public void init() throws IOException {
29         load(getDefaultReader());
30     }
31 
32     private String load(Reader reader) throws IOException {
33         StringBuffer sb = new StringBuffer();
34 
35         char[] buffer = new char[1024];
36         int length;
37         while ((length = reader.read(buffer)) > 0) {
38             sb.append(buffer, 0, length);
39         }
40         return sb.toString();
41     }

NPE.RET is reported for line 29, since the value returned by 'getDefaultReader()' call can be null and it is passed into the 'load(Reader reader)' method as a parameter, where it would be dereferenced.

Extension

This checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information.