473,413 Members | 1,733 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,413 software developers and data experts.

JDK 1.4.1 and 1.4.2 differ in compiling

public class Test {
static int returnValue() throws Exception {
while (true) {
try {
break;
} finally {
return 1;
}
}
}

public static void main(String args[]) throws Exception {
System.out.println(returnValue());
}
}

When I compile this in JDK 1.4.1_03, I get this error:-

Test.java:xx: missing return statement
protected static int returnValue() throws Exception {
^
1 error

When I compile this in JDK 1.4.2, I get a warning:-

Test.java:xx: warning: finally clause cannot complete normally
}
^
1 warning

JLS 14.14 says,

The preceding descriptions say "attempts to transfer control" rather
than just "transfers control" because if there are any try statements
(ý14.19) within the break target whose try blocks contain the break
statement, then any finally clauses of those try statements are
executed, in order, innermost to outermost, before control is
transferred to the break target. Abrupt completion of a finally clause
can disrupt the transfer of control initiated by a break statement.

My question is then what? Is it left to the compilers how they
interpret disruption of transfer of control? How can 1.4.2 generate a
class file when its an error for 1.4.1?

Thanks.

Arnab
Jul 17 '05 #1
1 2894
ar*********@infy.com (Arnab Nandi) wrote [snipped]:
static int returnValue() throws Exception {
while (true) {
try {
break;
} finally {
return 1;
}
}

When I compile this in JDK 1.4.1_03, I get this error:-

Test.java:xx: missing return statement
protected static int returnValue() throws Exception {
^
1 error
This is incorrect.
When I compile this in JDK 1.4.2, I get a warning:-

Test.java:xx: warning: finally clause cannot complete normally
}
^
1 warning
This is correct. Apparently, there was a bug in 1.4.1 that was fixed
in 1.4.2.
JLS 14.14 says,

The preceding descriptions say "attempts to transfer control" rather
than just "transfers control" because if there are any try statements
(ý14.19) within the break target whose try blocks contain the break
statement, then any finally clauses of those try statements are
executed, in order, innermost to outermost, before control is
transferred to the break target. Abrupt completion of a finally clause
can disrupt the transfer of control initiated by a break statement.

My question is then what? Is it left to the compilers how they
interpret disruption of transfer of control?


Not at all. Java2 Language Spec 14.19.2
(http://java.sun.com/docs/books/jls/s...oc.html#236653)
says, for the case illustrated:
"If execution of the try block completes abruptly for any other
reason R [meaning not a throw], then the finally block is executed.
Then there is a choice:
* If the finally block completes normally, then the try statement
completes abruptly for reason R.
* If the finally block completes abruptly for reason S, then the
try statement completes abruptly for reason S (and reason R is
discarded)."

Since the try block completes abruptly with a break (not a throw), and
the finally block completes abruptly with a return, then the try
statement completes abruptly with the return (reason S), and the break
(reason R) is discarded.

By the way, note that since (in the example given) the finally clause
will always be executed and will always execute the return statement,
it is impossible for that method to throw an exception. (In the
example, the return value is not calculated, and thus cannot throw an
exception).

==========
Now my occasional reminder to those on this newsgroup:

comp.lang.java is not an "official" newsgroup. It was replaced by more
specific newsgroups back in May of 1996. Most people don't see
postings on comp.lang.java, because only a few news servers still
carry it. Google Groups carries it for its historical value, and a few
ISPs (mainly cable-Internet providers) seem to carry it out of
ignorance :-)

The current worldwide Java newsgroups are:

comp.lang.java.3d 3D Graphics API's for the Java language
comp.lang.java.advocacy Support for and criticism of the Java System
comp.lang.java.announce Announcements re the Java System (Moderated)
comp.lang.java.beans Java software components (JavaBeans)
comp.lang.java.corba Topics relating to Java and CORBA
comp.lang.java.databases Databases, java.sql, JDBC, ODBC
comp.lang.java.gui GUI toolkits and windowing: AWT, IFC etc
comp.lang.java.help Set-up problems, catch-all first aid
comp.lang.java.machine JVM, native methods, hardware
comp.lang.java.programmer Programming in the Java language
comp.lang.java.security Security issues raised by Java
Jul 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Russell | last post by:
I'm trying to automate the comparison of some source code but I'm having trouble using the differ object. I'm new to Python so I'm probably doing something wrong. I've created a small program...
0
by: Martin Bless | last post by:
I need to access a MSSQL database (MS-Sql, not MySQL!)and would very much like to use mssql-0.09.tar.gz which is available from http://www.object-craft.com.au/projects/mssql/download.html ...
2
by: Rudy Ray Moore | last post by:
Hi guys, I just upgraded to "Visual Studio .net 2003 7.1 c++" from VS6. Some things I like (proper for loop variable scoping, for example), but some other things are troubling me. One...
10
by: Christina N | last post by:
When compiling my ASP.Net application, VS puts the new DLL under the local cached directory 'VSWebCache' in stead of on the server. How can I make it save the DLL file on the server when compiling?...
2
by: GRenard | last post by:
Hello, We just switch in our company to VisualStudio 2005 and the new ATL library. We use a wrapper to use CFileDialog. Its name is CFileDialogDeluxe Here the call CFileDialogDeluxe...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.