From alex.buckley at oracle.com Mon Mar 4 19:37:21 2019 From: alex.buckley at oracle.com (Alex Buckley) Date: Mon, 04 Mar 2019 11:37:21 -0800 Subject: Comment about Java SE 8 JLS (was Fwd: FWD: Java SE 8 Specs Typo) In-Reply-To: <01ea4bdd-3ebd-35b1-a42e-ff4ad966bd01@oracle.com> References: <6b237526-4310-48e5-9267-b64dfbf7d0f8@default> <01ea4bdd-3ebd-35b1-a42e-ff4ad966bd01@oracle.com> Message-ID: <5C7D7E71.8030705@oracle.com> The comment below was received from another channel. There seems to be a confusion between whether a statement can complete normally and whether a statement compiles. Also, between a `while` statement on the one hand, and a statement contained by a `while` statement on the other hand. If a `while` statement is reachable, then it can complete normally if its condition is not `true`. For example, `while (false){int x=5;}` can complete normally. Separately, the statement involving `x` which is contained by the `while` statement is not reachable, and an error is due for that. The claim "... the while statement does not compile when the condition is constant TRUE" is not implied. It is perfectly legal to loop forever by saying `while(true){int x = 5;}`. What is not legal is to have a statement after a known-infinite loop, because that statement is unreachable. Alex > Subject: Java SE 8 Specs Typo > From: Graeson Smith > Date: 2/28/2019 12:04 PM > To: javasedocs_us at oracle.com > > At Java SE 8, The Java Language Specifications, Java SE 8 Edition, Chapter 14 Section 21 > > Link: > https://docs.oracle.com/javase/specs/jls/se8/html/jls-14.html#jls-14.21 > > At Closed Bullet 13 After "These Rules are as follows", open bullet 1 > > Quote: > A while statement can complete normally iff at least one of the following is true: > The while statement is reachable and the condition expression is not a constant expression (?15.28) with value true. > > Assuming that the break; is there if necessary. According to the doc, the while statement will compile iff the condition is NOT CONSTANT TRUE. By extension, that means the while statement does not compile when the condition is constant TRUE. However, this is not the case. > while(true){//int x = 5;} will compile > while(false){//int x = 5;} will not compile > > This means that what it should say it: > "A while statement can complete normally iff at least one of the following is true: > The while statement is reachable and the condition is not a constant expression (?15.28) with value false." > > This revision will correlate correctly with the code demonstrated earlier in this email as well as the code at the end of section 14.21: > "while(false){ x = 3;}" which as stated results in a compile time error. > > To clarify, the code at the bottom of the section supports the correct specification of JAVA SE 8. However, the quote mentioned at the beginning of this email contradicts that code. > Thank you for your time > -Graeson