This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Product Version = NetBeans IDE 7.3 Beta 2 (Build 201211062253) Operating System = Linux version 2.6.32-5-686-bigmem running on i386 Java; VM; Vendor = 1.7.0_03 Runtime = Java HotSpot(TM) Client VM 22.1-b02 private void createBtnActionPerformed(java.awt.event.ActionEvent evt) { nota = new Note(); String text = noteTxt.getText(); String user = userFld.getText(); Calendar c = dataCal.getCalendar(); if(text.isEmpty() || user.isEmpty() || c == null) { JOptionPane.showMessageDialog(this, "You must fill all fields", "Error!", JOptionPane.ERROR_MESSAGE); nota = null; return; } Date date = c.getTime(); nota.setNote(text); # Causing Dereferencing possible null pointer nota.setDataNota(date); nota.setUtenteModifica(user); nota.setProprietario(user); dispose(); } As you can see in the example above, the line nota.setNote(text) cause Warning - Dereferencing possible null pointer but is impossible to have a null pointer exception here.
Created attachment 128620 [details] IDE log
Another test case from refactoring.java/src/org/netbeans/modules/refactoring/java/spi/ui/JavaRefactoringActionDelegate.java: JEditorPane pane = NbDocument.findRecentEditorPane(ck); result = pane != null; if (requiresSelection) { result = result && (pane.getSelectionStart() != pane.getSelectionEnd()); }
Created attachment 130205 [details] Another false positiv example Another false positiv example - see screenshot
Here's another case: public void main(){ double userInput = java.lang.Math.random(); Object o = null; if(userInput > .5){ o = new Object(); } assertion(o); //This will exit with an Error if o is null System.out.println(o.toString()); //Warning still displays here } public void assertion(Object o){ if(o == null){ throw new Error("o is null"); } } If I manually inline the code in the assertion(), the warning goes away.
Me too. Problem happens with the variable "query". We clearly test for a null value and return if that happens. But later, query.getBytes() raises that warning. public SearchRetrieveResponseType doRequest(SearchRetrieveRequestType request) throws ServletException { // stuff omitted String query = request.getQuery(); if(query==null || query.length()==0) return diagnostic(SRWDiagnostic.MandatoryParameterNotSupplied, "query", response); String resultSetID = getResultSetId(query); if (resultSetID!=null) { // got a cached result // omitted } else { // Evaluate the query. try { result = getQueryResult(query, request); } catch (InstantiationException e) { log.error("Exception "+e.getMessage()+" caught while doing query:"); try { log.error(Utilities.byteArrayToString(query.getBytes("UTF-8"))); } catch (UnsupportedEncodingException ex) { Logger.getLogger(SRWDatabase.class.getName()).log(Level.SEVERE, null, ex); } log.error("request: "+request); log.error(e, e); return diagnostic(SRWDiagnostic.GeneralSystemError, e.getMessage(), response); } }
This defect seems to be fixed in dev. The null assignment in the if-branch with `return' statement does not affect the possibly-null state in the rest of the method.
I have NetBeans IDE 8.1 (Build 201510222201) and the following false positive may still be observed: boolean hasParameters = true; final List<String> currentAuthorityValues = currentAuthorityParameters.get(parameterKey); //Null check, here! hasParameters &= currentAuthorityValues != null; //False warning for the below line for (String requiredValue : currentAuthorityValues) { .... }
(In reply to ememisya from comment #8) > I have NetBeans IDE 8.1 (Build 201510222201) and the following false > positive may still be observed: > > boolean hasParameters = true; > final List<String> currentAuthorityValues = > currentAuthorityParameters.get(parameterKey); > //Null check, here! > hasParameters &= currentAuthorityValues != null; > //False warning for the below line > for (String requiredValue : currentAuthorityValues) { > .... > } Err sorry forgot to include a line, better cases below: static class Test { List<String> value; public List<String> getValue() { return value; } public void setValue(List<String> _value) { value = _value; } } public static void main(String[] args) { Test test = new Test(); boolean hasParameters = true; final List<String> currentAuthorityValues = test.getValue(); //Null check, here! hasParameters &= currentAuthorityValues != null; //False warning for the below line if (hasParameters) { for (String requiredValue : currentAuthorityValues) { test.getValue(); } } } also static class Test { List<String> value; public List<String> getValue() { return value; } public void setValue(List<String> _value) { value = _value; } } public static void main(String[] args) { Test test = new Test(); final List<String> currentAuthorityValues = test.getValue(); boolean hasParameters = currentAuthorityValues != null; if (hasParameters) { for (String requiredValue : currentAuthorityValues) { test.getValue(); } } }