This is the mail archive of the java@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Libjava failures status


Tom Tromey wrote:
> 
> >>>>> "Jan" == Jan Hubicka <jh@suse.cz> writes:
> 
> Jan> The removal of code is other interesting issue I wasn't aware of.
> Jan> It means that if I write something like division by zero with
> Jan> unused result, Java specification says we must throw? (unlike C
> Jan> where such cases are usually undefined).
> 
> I believe that is the case.  I dug through the language spec a little
> but I couldn't find the definitive wording.

I think this qualifies as definitive:

11.1: "An exception is thrown for one of three reasons:
  "An abnormal execution condition was synchronously detected by the
Java virtual machine. Such conditions arise because: 
     "evaluation of an expression violates the normal semantics of the
language, such as an integer divide by zero, as summarized in §15.6"

15.6: "Run-time exceptions are thrown by the predefined operators as
follows:
    "An integer division (§15.17.2) or integer remainder (§15.17.3)
operator throws an ArithmeticException if the value of the right-hand
operand expression is zero."

So, this method must throw an ArithmeticException, even though i2 is
never used (for that matter, i1 is only used in generating the throw),
because every reachable expression along a control flow path must be
evaluated:

void m()
{
  int i1 = 0;
  int i2 = i1 / i1;
}

Still, in spite of these requirements, the JLS also provides this caveat
to programmers:

15.7: "The Java programming language guarantees that the operands of
operators appear to be evaluated in a specific evaluation order, namely,
from left to right.
"It is recommended that code not rely crucially on this specification.
Code is usually clearer when each expression contains at most one side
effect, as its outermost operation, and when code does not depend on
exactly which exception arises as a consequence of the left-to-right
evaluation of expressions."

> 
> Jan> Thanks for clarification, I guess I should browse trought the
> Jan> Java standard to understand the issue better.
> 
> I believe they are available online.

http://java.sun.com/docs/books/jls/index.html
http://java.sun.com/docs/books/vmspec/index.html

-- 
This signature intentionally left boring.

Eric Blake             ebb9@email.byu.edu
  BYU student, free software programmer


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]