NPE.RETA 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 115 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. Related checkersExtensionThis checker can be extended through the Klocwork knowledge base. See Tuning Java analysis for more information. |