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 247099 - proposal to remove redundant cast is wrong
Summary: proposal to remove redundant cast is wrong
Status: RESOLVED FIXED
Alias: None
Product: java
Classification: Unclassified
Component: Hints (show other bugs)
Version: 8.0.1
Hardware: PC Windows 7
: P3 normal (vote)
Assignee: Svata Dedic
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-09-14 14:27 UTC by ngx472
Modified: 2015-09-17 01:26 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 ngx472 2014-09-14 14:27:11 UTC
in the example below

public void castTest() {
    int i = 12312, k = 313;
    System.out.println("=" + ((float) i / (float) k));
    System.out.println("=" + (i / k));
  }
-->
95321
1006

Removing the (float) cast as proposed by the hint leads to a different behavior of the code. This hint is therefore wrong on such cases.
Comment 1 Svata Dedic 2015-09-15 12:24:08 UTC
I have attempted to suppress the 'remove cast' hint+fix for right operand of a binary op, if 
a) the reundant cast is reported for the left operand, and
b) both casts are the same.

This does not cover all situations, but should be sufficient for many situations

Implemented in jet-main#a8dca55b66bd
Comment 2 Quality Engineering 2015-09-17 01:26:38 UTC
Integrated into 'main-silver', will be available in build *201509170002* on http://bits.netbeans.org/dev/nightly/ (upload may still be in progress)

Changeset: http://hg.netbeans.org/main-silver/rev/80875e9b41f1
User: Svata Dedic <sdedic@netbeans.org>
Log: #247099: only one of two casts in a binary op is suggested for removal