Menu

#546 "Run Document's Main Method" allows non-void return type

3: Ugly
closed-fixed
7
2009-08-12
2006-10-26
Marty Stepp
No

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.)

Discussion

  • Marty Stepp

    Marty Stepp - 2006-10-26

    short program to reproduce the bug

     
  • Dan Smith

    Dan Smith - 2006-10-26

    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).

     
  • Dan Smith

    Dan Smith - 2006-10-26
    • labels: 389638 --> DynamicJava
     
  • Mathias Ricken

    Mathias Ricken - 2008-06-12
    • assigned_to: nobody --> dlsmith
     
  • Mathias Ricken

    Mathias Ricken - 2008-06-12

    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!
    >

     
  • Mathias Ricken

    Mathias Ricken - 2008-07-08
    • priority: 5 --> 7
     
  • Mathias Ricken

    Mathias Ricken - 2008-07-08
    • milestone: 173642 --> 3: Ugly
     
  • Mathias Ricken

    Mathias Ricken - 2009-08-10

    Still exists as of 4978.

     
  • Dan Smith

    Dan Smith - 2009-08-12

    Fixed with r4986. The generated "main" call is preceded by a reflection-based check that verifies the method's signature.

     
  • Dan Smith

    Dan Smith - 2009-08-12
    • status: open --> closed-fixed
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.