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 247780 - Invalid hint "if statement is redundant"
Summary: Invalid hint "if statement is redundant"
Status: NEW
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.1
Hardware: PC Linux
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on: 249320
Blocks:
  Show dependency tree
 
Reported: 2014-10-07 19:48 UTC by mclaborn
Modified: 2015-09-10 13:58 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 mclaborn 2014-10-07 19:48:45 UTC
Product Version = NetBeans IDE 8.0.1 (Build 201408251540)
Operating System = Linux version 3.13.0-36-generic running on amd64
Java; VM; Vendor = 1.7.0_67
Runtime = Java HotSpot(TM) 64-Bit Server VM 24.65-b04

Getting an invalid hint:  "The if statement is redundant".

public boolean applies(Date a_date) {
  if (a_date.before(getStartdate())) {
    return false;
  }
  if (a_date.after(getEnddate())) {  // hint show on this if statement
    return false;
  }
  return true;
}
Comment 1 Jiri Prox 2014-10-24 07:34:36 UTC
What is wrong with the hint?
The return statement and the last if can be combined into single return.
Comment 2 mclaborn 2014-10-24 13:10:35 UTC
What you say is true.  The hint "fixer" changes it to this:

return !(a_range.getEnddate() != null && a_date.after(a_range.getEnddate()));

which is accurate, but is in my opinion much harder to read.

In the original the if statement is not redundant.  It is coded that way as a personal coding style preference.

It may be a matter of semantics with the word "redundant" or simply a coding style preference.
Comment 3 mclaborn 2014-10-24 13:14:17 UTC
Sorry, I used the wrong method in my previous comment.  The hint "fixer" changes it to:

return !a_date.after(getEnddate());
Comment 4 Svata Dedic 2015-09-10 13:58:38 UTC
In order to fix this, the IDE needs to know that after() returns always non-null