NPE.STATA 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.STAT is reported for the result of a method call being dereferenced when the source code of the method is unavailable, but statistics indicate that it can return null. Statistics are gathered for the null checks applied to the values returned by methods. Example 122 public void printAbsoluteParentPath() { 23 final File parent = f.getParentFile(); 24 if (parent != null) { 25 String absolutePath = parent.getAbsolutePath(); 26 System.out.println("absolute path " + absolutePath); 27 } 28 } 29 30 public void printCanonicalParentPath() throws IOException { 31 final File parent = f.getParentFile(); 32 if (parent != null) { 33 String canonicalPath = parent.getCanonicalPath(); 34 System.out.println("canonical path: " + canonicalPath); 35 } 36 } 37 38 public void printParentPath() throws IOException { 39 String path = f.getParentFile().getPath(); 40 System.out.println("path " + path); 41 } NPE.STAT is reported for line 39, since the value returned by 'getParentFile()' is usually checked for null before dereferencing, so there is a possibility of an NPE here. Related checkersExtensionThis checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information. |