This bug applies to DrJava's newest version
20061025-1556 and the preceding version 20060918-1737,
on all platforms.
The DrJava option to "Run Document's main Method" does
not behave correctly. It incorrectly considers any
static method with a name of "main" and a sole
parameter of a String[] to be acceptable, regardless of
whether its return type is void. For example, the
following program can be compiled and executed
successfully in DrJava (note the return type of double
on main):
public class Bad {
public static double main(String[] args) {
System.out.println("Hello, world!");
return 0.0;
}
}
The reason this is a big problem is that, though our
students write their programs in DrJava, we grade them
at the command line by scripts. Several students have
submitted programs like the above, which compile and
run perfectly in their DrJava, but which do not run at
all when using standard javac/java at the command line.
(It gives NoSuchMethodDefError: main.)
short program to reproduce the bug
Logged In: YES
user_id=1060117
I've moved this into the DynamicJava category. This is a language problem -- the interpreter doesn't faithfully
match the language spec on this (or, probably more accurately, the interpreter doesn't match the behavior of
Sun's interpreter -- this probably isn't something described in the JLS).
Logged In: YES
user_id=1075744
Originator: NO
As of revision 4513, this bug still exists:
> public class Bad {
public static double main(String[] args) {
System.out.println("Hello, world!");
return 0.0;
}
}
> java Bad
Hello, world!
>
Still exists as of 4978.
Fixed with r4986. The generated "main" call is preceded by a reflection-based check that verifies the method's signature.