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

Summary: proposal to remove redundant cast is wrong
Product: java Reporter: ngx472 <ngx472>
Component: HintsAssignee: Svata Dedic <sdedic>
Status: RESOLVED FIXED    
Severity: normal    
Priority: P3    
Version: 8.0.1   
Hardware: PC   
OS: Windows 7   
Issue Type: DEFECT Exception Reporter:

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