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 228333 - Wrong "Unnecessary test for null" hint
Summary: Wrong "Unnecessary test for null" hint
Status: RESOLVED DUPLICATE of bug 227954
Alias: None
Product: editor
Classification: Unclassified
Component: Hints & Annotations (show other bugs)
Version: 7.3.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Jan Lahoda
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-04-06 12:28 UTC by everflux
Modified: 2013-04-15 09:32 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description everflux 2013-04-06 12:28:51 UTC
I have a maven based Java 7 project.

Given

final String fileName = "/" + resource + ".txt";
InputStream inputStream = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName);
        
final Path resourcePath = Paths.get("src/test/resources"+fileName);
if(inputStream == null && Files.exists(resourcePath, LinkOption.NOFOLLOW_LINKS))
{
  inputStream = new FileInputStream(resourcePath.toFile());
}
if (inputStream == null) // "Unnecessary test for null, the expression is never null" hint
{
    inputStream = new FileInputStream("src/main/resources" + fileName);
}

The hint that "inputStream" can not be null is wrong, since the condition above may result in "inputStream == null, file exist == false".

If I change it to

if(inputStream == null && true)
{
   inputStream = new FileInputStream(resourcePath.toFile());
}
if (inputStream == null)
{
   inputStream = new FileInputStream("src/main/resources" + fileName);
}

the hint vanishes, even if it would now make sense.
Comment 1 Jan Lahoda 2013-04-15 07:56:35 UTC
What exact NB version is that? I tried to reproduce on a recent trunk build, on 7.3 and updated 7.3, and did not see the bug. Is there some more information I could use to reproduce?

Thanks.
Comment 2 everflux 2013-04-15 08:04:29 UTC
Product Version: NetBeans IDE 7.3 (Build 201302132200)
Java: 1.7.0_17; Java HotSpot(TM) 64-Bit Server VM 23.7-b01
Runtime: Java(TM) SE Runtime Environment 1.7.0_17-b02
System: Linux version 3.5.0-28-generic running on amd64; UTF-8; en_US (nb)

Using embedded maven, maven language level set to 1.7
Using features on deman (full IDE install)

IDE Platform plugin
Version: 1.22.1 Source: NetBeans IDE 7.3 (Build 201302132200) 

Java Plugin
Version: 1.21.1 Source: NetBeans IDE 7.3 (Build 201302132200) 

RCP Platform
Version: 1.20.1 Source: NetBeans IDE 7.3 (Build 201302132200)
Comment 3 Jan Lahoda 2013-04-15 09:32:18 UTC
Appears to be duplicate of bug #227954.

*** This bug has been marked as a duplicate of bug 227954 ***