JDK-4039419 : Possibly invisible loss of precision can cause endless loops
  • Type: Enhancement
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.1
  • Priority: P4
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_2.5
  • CPU: sparc
  • Submitted: 1997-03-17
  • Updated: 2024-10-09
  • Resolved: 2020-06-11
Related Reports
Relates :  
Description

Name: sgC58550			Date: 03/17/97


I do think the compiler should warn when int (long) ist 
implicitely converted to float (double). I got an endless
loop which was not so easy to find. Basically the following 
code shows what happens:

class Test {
    public static void main(String argv[]) {
        int i;
        float j=1;
        for(i=0;i<33554432;i+=j)                      
            if (i % 1000000 == 0) System.out.print(i);
    }
}

With today's computation power and memory sizes a loop of
this proportion is not so unlikely. The ultra I use arrives 
at the problematic point in less than a  minute.
Considering that the only "error" in the above is the 
declaration of j as int, I consider this "feature" to be 
dangerous. If someone wants to conserve memory such an use
of a float is not so unlikely. As this problem is possibly 
not found in a test-run (small values) but will cause trouble
when it counts (large values), I belive an appropriate warning
or even a required cast should be added.

Best Regards 
Arno Wagner
(Dipl. Inform.) 


company - Univesity of Karlsruhe, Dept. of Informatics , email - ###@###.###
======================================================================

Comments
EVALUATION The various conversions which may lose information could be flagged by javac as part of ongoing work to improve compiler diagnostics.
30-07-2008

EVALUATION Not a bug. Not a feature to be added either.
11-06-2004

WORK AROUND Name: sgC58550 Date: 03/17/97 Be very careful and know that the problem exists. ======================================================================
11-06-2004

PUBLIC COMMENTS Request to change numeric conversions so a warning is issued when converting long to double. Rejected.
10-06-2004