By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,640 Members | 2,077 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,640 IT Pros & Developers. It's quick & easy.

No warning or error from Sun Java compiler

P: n/a
/*

Test4

WARNING THIS PROGRAM NEVER ENDS DUE TO JAVA COMPILER ERROR

Neither Sun JDK 1.1.8 nor JDK 1.4.1 compiler will output *any* error or warning

A disassembly of the class file shows no reference to the readyInst label.

Friday, March 19th, 2004
Mark A. Washburn

*/
public class Test4 {

final static short m[] = {
-1, -2, -3,
};

static boolean bGone = false;

public static void main(String args[]) {
long inst = 0;
short ip = 0;

exitInterpreter:
while (!bGone) {
try {
while (true) {
inst = m[ip++];
System.out.print(" inst = " + inst + "\n");

readyInst: {
switch (-((short) inst)) {
case 1:
break;

case 2:
break;

case 3:
inst = -4;
if (inst < 0) {
break readyInst;
}
break;

case 4:
bGone = true;
continue exitInterpreter;

default:
break;
}
}
}
} catch (Exception e) {// array out of bounds error
// System.out.print("\nException: " + e.toString() + "\n" );
}
}

System.out.print
(" Your compiler resolved the /break readyInst;/ statement.\n");

}

}
Jul 17 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Mark A. Washburn wrote:
WARNING THIS PROGRAM NEVER ENDS DUE TO JAVA COMPILER ERROR

I don't see any error. readyInst is a label on a simple block that
contains a switch statement. The labelled break causes the compiler to
immediately exit that simple block, and therefore to immediately reach
the end of your while loop. The while loop condition evaluates to true,
and the loop continues.
Neither Sun JDK 1.1.8 nor JDK 1.4.1 compiler will output *any* error or warning


There is no error. The code you wrote makes perfect sense, except for
not doing what you seem to think it should.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
Jul 17 '05 #2

P: n/a
Mark A. Washburn wrote:
/*

Test4

WARNING THIS PROGRAM NEVER ENDS DUE TO JAVA COMPILER ERROR
Never ends, yes. Compiler error, no.
Neither Sun JDK 1.1.8 nor JDK 1.4.1 compiler will output *any* error or warning
Because there isn't any.
A disassembly of the class file shows no reference to the readyInst label.


Disassembly from the 1.4.2_02 compiler shows such a reference, although
the end of simple block labelled by readyInst corresponds with the end
of the while(true) loop, and hence the compiler skips the extra goto and
goes directly to the loop top. It does exactly the same thing for the
unlabelled breaks, which is just fine.

Try running it in a debugger to see why it never ends, if you can't
figure it out from studying the source. Alternatively, start by
considering why and how you think it _should_ end, and see whether you
can see any reason why it might not do that, or why the behavior you
expect might not result in the program ending. From the other
direction, consider the question of what the program _does_ do if it
doesn't end.

I leave it to you to work out the details.
P.S.: Experienced programmers know that although compilers do have bugs,
unexpected program behavior is almost always the result of incorrect
code. I know personally that the more experience I gain, the more ways
of writing bad code I discover. Thankfully, the novel ones are getting
fewer and farther between :-) . On the other hand, I have never
discovered a bug in any of the many compilers for various languages that
I have used over the years.
John Bollinger
jo******@indiana.edu

Jul 17 '05 #3

P: n/a
"Chris Smith" <cd*****@twu.net> wrote in message
news:MP************************@news.pop4.net...
Mark A. Washburn wrote:
WARNING THIS PROGRAM NEVER ENDS DUE TO JAVA COMPILER ERROR


I don't see any error. readyInst is a label on a simple block that
contains a switch statement. The labelled break causes the compiler to
immediately exit that simple block, and therefore to immediately reach
the end of your while loop. The while loop condition evaluates to true,
and the loop continues.
Neither Sun JDK 1.1.8 nor JDK 1.4.1 compiler will output *any* error or warning


There is no error. The code you wrote makes perfect sense, except for
not doing what you seem to think it should.

Agreed. The code does what it's supposed to, and if, as the OP claims, the
class file shows no reference to readyInst, it's because it was optimized
away. At that point in the switch, "break readyInst" is identical to simply
"break".
Jul 17 '05 #4

P: n/a
John C. Bollinger wrote:
P.S.: Experienced programmers know that although compilers do have bugs,
unexpected program behavior is almost always the result of incorrect
code.
Agreed.

On the other hand, I have never
discovered a bug in any of the many compilers for various languages that
I have used over the years.


I can only suppose that either you have the luck of the very Devil himself, or
that you've been hand-assembling everything for years ;-)

(I think I've been averaging about 0.5 per year over my career to date...)

-- chris
Jul 17 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.