How does Jikes process programs differently from other compilers?
Here are a few examples of constructs that Jikes handles according to specifications. See the FAQ included in the download for more examples.
[
Extraneous Semicolons. Your program may contain extraneous semicolons that are silently ignored by many compilers. Jikes treats then as cause to issue a warning. You can use the -nowarn option to suppress these warnings.
Unreachable Statements. It is a compile-time error if a statement cannot be executed because it is unreachable (section 14.19). Many compilers don't properly detect unreachable statements, and accept programs such as the following (which Jikes rejects):
- class Test {
- void method(boolean b) {
- if (b) return;
- else return;
- b = !b;
}
- }
Another example, and one that confuses many users, is shown by the following program:
- class Test {
- public static void main(String[ ] args){
- try {
- }
- catch (Exception e) {
- System.out.println("caught");
- }
- }
- }
Jikes accepts this program but issues the warning:
catch (Exception e) {
<--------->
*** Warning: This catch block is unreachable: there is no exception whose type is assignable to "java/lang/Exception" that can be thrown during execution of the body of the try block.
See Section 14.1: since execution of the (empty) try block can throw no exception, the catch block is not reachable. Jikes will detect similar errors, even when the try block is not empty, based on its analysis of the program. (This is one area where the specification is a bit murky, and this murkiness is the reason Jikes treats this as cause for issuing a warning and not an error.)
Definite Assignment. Some compilers accept the following program:
- public class Test {
- public static void main(String args[ ]) {
- L1: for (int i = 1; i < 11; i++) {
- int j = 1,
- k;
- L2:
- do {
- if (j == i)
- continue L1;
- j++;
- k = 0;
- } while (j < 10);
- int l = k; // an error should be emitted here !
- }
- }
- }
which Jikes rejects:
int l = k; // an error should be emitted here !
*** Semantic Error: The variable "k" is accessed before having been
definitely assigned a value
Problems with break Statement. Many compilers have trouble with the following program. Some crash during compilation; others complain about a missing
label:
class Test {
- public static void main(String[ ] args) {
- Label:
- try {
- }
- finally {
- break Label;
- }
- }
- }
Jikes accepts this program.