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 238286 - "The if statement is redundant." seems to be backwards.
Summary: "The if statement is redundant." seems to be backwards.
Status: RESOLVED DUPLICATE of bug 254445
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 7.4
Hardware: Macintosh Mac OS X
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-11-13 02:09 UTC by TradeIdeasPhilip
Modified: 2016-03-19 20:37 UTC (History)
0 users

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 TradeIdeasPhilip 2013-11-13 02:09:16 UTC
I got a warning saying "The if statement is redundant".  I reduced it to the following test code.  It's completely repeatable.

    private boolean test1(Object a)
    {   // This has no warning, but it probably should have a warning.
        if (null == a)
            return false;
        return false;
    }
    
    private boolean test2(Object a)
    {   // This warns me "The if statement is redundant."  But it is not true!
        if (null == a)
            return false;
        return true;
    }
Comment 1 Jiri Prox 2013-11-13 07:09:28 UTC
The second if can be replaced by single return statement, as you can see when you apply the hint. That is why the hint is provided

The first case is not detected to by the hints infrastructure to be redundant ->
turning this to the enhancement
Comment 2 TradeIdeasPhilip 2013-11-13 17:57:42 UTC
Oh, I see.  Thank you.

No, I'm not asking for the first case to be a hint.  I was just confused by the message.

FYI, my original code looked a little more like this:

    boolean interesting(int a, int b)
    {
        if (a == b * 42)
            // The Douglas Adams.
            return true;
        if (b == a * 42)
            // The reverse Douglas Adams.
            return true;
        if (a == b * 420)
            // It's 4:20, dude!
            return true;
        return false;
    }

Accepting the hint would make the code smaller, but less readable.  I'll just disable that hint.
Comment 3 supuhstar 2016-03-19 20:37:55 UTC
Although this is older, it doesn't seem to properly understand, describe, or propose a resolution to the core problem.

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