JDK-4089107 : javac treats integer division by (constant) zero as an error.
  • Type: Bug
  • Component: tools
  • Sub-Component: javac
  • Affected Version: 1.1.4
  • Priority: P4
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_95,windows_nt
  • CPU: x86
  • Submitted: 1997-10-28
  • Updated: 1999-01-15
  • Resolved: 1999-01-15
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
Other
1.2.0 1.2beta4Fixed
Related Reports
Relates :  
Description
The original description of this bug does not seem to match the synopsis.  The following program does:

public class zero {
    public static void main(String[] args) {
	System.out.println(1/0);
    }
}

Running the above yields:


zero.java:3: Arithmetic exception.
        System.out.println(1/0);
                            ^
1 error

-------
Here is the original description for this bug, which more properly is described by bugid 4019304:

class UofO {
    private float value = 10;
    private static final float one_sixth_inch = (float)((1/6)*0.0254);

    public float getm() { return value; }

    public float this_compiles() {
	float val = one_sixth_inch;
	return getm() / val; 
    }
    public float this_doesnt_compile() {
	return (getm() / one_sixth_inch);
    }
}

Comments
CONVERTED DATA BugTraq+ Release Management Values COMMIT TO FIX: 1.2beta4 FIXED IN: 1.2beta4 INTEGRATED IN: 1.2beta4
14-06-2004

WORK AROUND Name: tb29552 Date: 10/28/97 ======================================================================
11-06-2004

EVALUATION Well, hate to say it, but the bug provided in the description doesn't appear to agree with the synopsis. Instead, the description seems to match up with bug 4019300, which is that floating-point division by (constant) zero is treated as a compile time error when it should not be. Curious, I wrote the following little program: public class zero { public static void main(String[] args) { System.out.println(1/0); } } It did indeed stop compilation with the following error: zero.java:3: Arithmetic exception. System.out.println(1/0); ^ 1 error I am currently looking through the JLS to see if it specifies what should happen if an arithmetic exception is raised while computing a constant expression. My suspicion is that it does not. If this isn't specified, then I believe it would be reasonable for the code to compile and generate the exception at runtime. I will do some research to be sure. If you are interested in this bug, please take a look at 4019300, which is the analogous bug with the modulus operation, and 4019304, which is a similar bug having to do with constant floating point division. todd.turnidge@Eng 1997-10-28 This has been fixed. See 4019300, 4019304 for more info. todd.turnidge@Eng 1998-02-10
28-10-1997