This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes error not caught at compile or run-time Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "error not caught at compile or run-time" Watch "error not caught at compile or run-time" New topic
Author

error not caught at compile or run-time

Thomas White
Ranch Hand

Joined: Feb 01, 2003
Posts: 32
Hi,
Could anyone give me an example of an error that violates the Java language definition (not a logic error)that might not be caught at compile time or run-time?
Thanks,
Thomas
Wayne L Johnson
Ranch Hand

Joined: Sep 03, 2003
Posts: 399
Is this a trick question? If it isn't caught at compile time or run time, i.e., it compiles and runs [correctly], can it be an error?
Can you be more specific as to what you are looking for? Are you trying to see if you can "break" the JVM by getting it to run illegal code? What?
Thomas White
Ranch Hand

Joined: Feb 01, 2003
Posts: 32
No, its not a trick question, its part of a homework assignment found in Michael Scott's "Programming Language Pragmatics" exercise 1.1 part e.
Your supposed to pick your favorite programming language and for part e
give and example of " an error that the compiler can neither catch nor easily generate code to catch(this should be a violation of the language definition, not just a program bug) ". I think an example is easier to find in C, for example a pointer that references garbage in memory, then again, thats not neccesarily a violation of the programming language definition either. I'm having a tough time with this one. I know that Scott's book is popular. Has anyone come up against this question?
Thanks,
Thomas
Ivan Jouikov
Ranch Hand

Joined: Jul 22, 2003
Posts: 269
Thats the stupidest thing I've ever heard.
Thomas White
Ranch Hand

Joined: Feb 01, 2003
Posts: 32
Well... Michael Scott is considered an authority on programming/compiler implementation. I don't know, maybe the the Java compiler is just that efficient that the problem doesn't apply. But then again, maybe there's something about the language/compiler that you or I don't know about.
Joel McNary
Bartender

Joined: Aug 20, 2001
Posts: 1817

So long as you language is well-formed, I cannot think of a situation where you can have a language error that the compiler cannot catch. Now, programming errors are a dime a dozen --- both in terms of "no, that's not to spec," and "no, that will cause a segmentation fault/core dump/GPF/global nuclear annilhilation/whatever." But those do not strike me as "violation of the language definitions", they strike me as "programming bugs."
Of course, I've never read his book, so I'm afraid that I don't know how he is defining his terminology.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
Ernest Friedman-Hill
author and iconoclast
Marshal

Joined: Jul 08, 2003
Posts: 24183
    
  34

I thought I gave a good answer in this thread.


[Jess in Action][AskingGoodQuestions]
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Could anyone give me an example of an error that violates the Java language definition (not a logic error)that might not be caught at compile time or run-time?
Perhaps you are looking for something like this. From Java Language Specification: "It is a compile-time error if a statement cannot be executed because it is unreachable."
Yet the statement if (false) { x = 10; } compiles without error, although "x=10" is clearly unreachable. While it may appear that this is a direct and brutal violation of the JLS, it is really not, as JLS actually treats the if (flag) as a special case to allow easier debugging.
Thomas White
Ranch Hand

Joined: Feb 01, 2003
Posts: 32
Hi Eugene,
Thanks, thats a great example
John Smith
Ranch Hand

Joined: Oct 08, 2001
Posts: 2937
Here is another example, a bit more complex, but also much more dramatic.
Private methods cannot be invoked from outside of the class according to the rules, right? Well, kinda, -- you can bend the rules:

Output:
very private method was successfully invoked and executed
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
This maybe isn't the greatest example, but...
The current Java language doesn't allow typed collections, without writing a special collection class. So, the Collections API just handles a bunch of ol' java.lang.Objects, often requiring casts when an object is retrieved. I'm sure more than one java.lang.ClassCastException has bothered a Java developer.
Of course, this won't be such an issue with Java 1.5 and generics.
[ September 14, 2003: Message edited by: Dirk Schreckmann ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
Thomas White
Ranch Hand

Joined: Feb 01, 2003
Posts: 32
Dirk and Eugene,
Thanks for both your excellent examples. Eugene, I think your last example comes closest to addressing the problem from Scott's book.
The JLS states:
A private class member or constructor is accessible only within the class body in which the member is declared and is not inherited by subclasses.

Yet with reflection we have an example in the Java API where you can violate the language specification on private level access and get away with it.
Thanks for all your examples,
Thomas
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: error not caught at compile or run-time
 
Similar Threads
array
KAM India Edition Question 6.27
Runtime and compile time errors
error in eclipse