Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8046828

sjavac Main class should be more API/test friendly

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 9
    • 9
    • tools

      sjavac.Main.main continues non-trivial work and two calls of System.exit().

      It is better practice to structure such code into a method (often called run) which does the same work but instead of calling System.exit, simply returns an exit code and/or throws exceptions instead. In other words, code is better structured as

      void main(String... args) {
          Main m = new Main();
          try {
              int rc = m.run(args);
              System.exit(rc);
          } catch (Exception e) {
              System.exit(ERROR);
          }
      }

      This makes it much easier to write test programns which can call the run method without having to worry about it calling System.exit

            alundblad Andreas Lundblad (Inactive)
            jjg Jonathan Gibbons
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: