473,386 Members | 1,819 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,386 software developers and data experts.

No warning or error from Sun Java compiler

/*

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
4 2140
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
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
"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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Jagdeesh | last post by:
Hai Colleagues, I am using Tomcat 4.1.24 and JDK 1.4.0_03 in my winXP machine. I've transferred a set of folders(containing jsp files) into tomcat's webapps directory(to /webapps/bob ,...
4
by: thule | last post by:
Okay, thanks to John (THANK YOU SO MUCH). I switched all my header files over to using the new Standard <iostream> and included the using namespace std; . This seems to have fixed all the errors I...
4
by: DFP | last post by:
I am posting the gcc 3.3.2 compiler error and the source lines below them. Please explain this warning and how to fix it. crt/crtmap.hpp:17: warning: `std::map<K, D, C,...
3
by: Bryan Parkoff | last post by:
I tell C++ Compiler to use level 4 warning instead of level 3 warning so all variables can be calculated accuracy with no prone error. It will give you a warning like this. unsigned short A =...
27
by: MK | last post by:
I am a newbie. Please help. The following warning is issued by gcc-3.2.2 compiler (pc Linux): ================================================================== read_raw_data.c:51: warning:...
11
by: zeppe | last post by:
Hi all, I've a problem. The code that follows creates a warning in both gcc and visual c++. However, I think it's correct: basically, there is a function that return an object of a derived...
3
by: Vittorix | last post by:
Hi all, I'm talking about of the following warning: "myClass.java uses unchecked or unsafe operations. Note: Recompile with -Xlint:unchecked for details." Usually when this warning occours...
2
by: BSeab1024SE | last post by:
In MS Visual C++ some code I wrote generated the warning "conversion from 'int' to 'const float', possible loss of data." In the process of trying to determine if I could rewrite the code to...
20
by: jacob navia | last post by:
Consider this code static typedef struct { int boo; } FOO; This provokes with MSVC: ------------------------------ Microsoft (R) C/C++ Optimizing Compiler Version 14.00.50727.762 for x64...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.