Community
Participate
Working Groups
When I enable 'Null reference: Warning' in Java|Compiler|Errors/Warnings it seems, that the content of a try block is ignored and thus leads to wrong warnings. E.g.: private String bla(StreamSource src) { String vers = null; XMLStreamReader in = null; try { in = Stax.getReader(src, "details"); if (in == null) { return null; } vers = in.getAttributeValue(null, "version"); while (in.hasNext()) { in.next(); } } catch (XMLStreamException e) { log.warn(in.getLocation() + ": " + e.getLocalizedMessage()); vers = null; } finally { if (in != null) { try { in.close(); } catch (Exception e) { /**/ } } try { src.getInputStream().close(); } catch (Exception e) { /**/ } } return vers; } The IDE issues a false warning for in and vers references in the catch block ...
Assuming that getReader (and no other method used into the try block) bears a 'throws XMLStreamException' clause, then the only way to get into the catch block is to fail into getReader, and to bypass the assignment to in (and vers). Hence the beginning of the catch block sees vers and in as they are at the top of the method, that is null. This is only an example of what could explain the described behavior. There may still be a bug though. Please reopen with further information (which methods throw what) if you believe so.
Sorry, forgot to mention it :(: Stax.getReader does not throw any checked exception. Only the in.next() in the while block may throw an XMLStreamException ...
Reproduced, thanks.
The problem pertains to unchecked exceptions. Unchecked exceptions are reachable from any point in the try block, just like finally is. Accordingly, we must mitigate the null info made available to the catch block, leveraging the current flow context initsOnFinally member. Adding test cases NullReferenceTest 525->527. Will post a patch when releasing (in order to avoid posting a cumulative patch). Waiting for 3.3 M2 to be declared.
Created attachment 50812 [details] Fix + test cases for this bug + bug 158000 The fix essentially mitigates unchecked exceptions flow info with the initsOnFinally value so as to take into account all possible exit points. Re. 158000, erroneous return statements have been replaced by continue statements as needed.
Realeased for 3.3M3.
*** Bug 151083 has been marked as a duplicate of this bug. ***
*** Bug 159401 has been marked as a duplicate of this bug. ***
Comment 6 should read "Released for 3.3M3." instead.
Verified for 3.3 M3 using warm-up build I20061030-0010