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.

Bug 254481 - Non Report Of NullPointer Exception
Summary: Non Report Of NullPointer Exception
Status: RESOLVED WONTFIX
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.2
Hardware: PC Windows 8.1
: P4 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks: 249320
  Show dependency tree
 
Reported: 2015-08-18 12:24 UTC by bolo
Modified: 2015-11-13 11:37 UTC (History)
1 user (show)

See Also:
Issue Type: ENHANCEMENT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description bolo 2015-08-18 12:24:23 UTC

    
Comment 1 bolo 2015-08-18 12:32:15 UTC
//Ok. I may not be able to attach a test case on this issue. However

//Example
1.  ArrayList array= new ArrayList[4];

//if I try to add an object to the first variable
2. array[1].add("1");

//An experienced java programmer knows that he needs to add the following before //the above code
3. array[1] = new ArrayList();

//Otherwise he gets a NullPointer Exeption at the second code. 

//REPORT. There is no Null pointer thrown at that second code. It was very //painful that I had to take four days because of this.
Comment 2 Svata Dedic 2015-10-05 10:52:28 UTC
Not an editor issue, rather code analysis issue.

Also such inspection will work just in trivial cases, such as the one presented in the report. Consider code, when the created array is passed to an arbitrary method (e.g. on a different class, to make things more clear). There are no assumptions on what the method can do with the array contents, so it could as well assign its members.

In such cases the inspection could generate a false positive -> annoy the programmer.

Other counter-example would be code like:
ArrayList[] array= new ArrayList[4];
for (int i = 0; i < 2; i++) { // typo in the upper bound
  array[i] = new ArrayList();
}
array[3] = new ArrayList(); // produces NPE despite array[i] assignment

I'll think how to incorporate this in the data flow algorithm rewrite, but I don't give it a priority
Comment 3 Svata Dedic 2015-11-13 11:37:02 UTC
Sorry, will not fix -- detection of array item nullability is too fragile.