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.

Security training

Application security training materials provided by Secure Code Warrior.

Extension

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