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.CONST

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.CONST is reported for an attempt to dereference a variable that was initialized with a null constant.

Example 1

15     static String searchForMaxString(final String text) {
16         if (text == null) return null;
17         int max = 0;
18         StringTokenizer tok = new StringTokenizer(text, ":");
19         String found = null;
20         while (tok.hasMoreTokens()) {
21             String x = tok.nextToken();
22             if (x.length() >= max) {
23                 max = x.length();
24                 found = x;
25             }
26         }
27         int len = found.length();
28         System.err.println(len + " -> " + found);
29         return found;
30     }

NPE.CONST is reported for line 27 since the null value was assigned to variable 'found' on line 19.

Extension

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