lint warning for exception in initializer

XMLWordPrintable

    • Type: Enhancement
    • Resolution: Rejected
    • Priority: P4
    • None
    • Affects Version/s: 7
    • Component/s: tools
    • generic
    • generic

      In 6964607 a customer suggests that initializers should be guaranteed to complete normally (rather than throwing an exception). While the JLS only requires that an initializer *can* complete normally, it's good practice to *always* complete normally -- the non-obvious effect of an initializer throwing an exception is to possibly cut short the evaluation of constructor code, field initialization, or other initializers.

      It would be reasonable to introduce a lint warning that reports a problem whenever an initializer (static or instance) contains a throw statement. One compication is that the programmer may be safely catching the exception within the initializer -- a more complete analysis would look for thrown types are not caught.

            Assignee:
            Unassigned
            Reporter:
            Dan Smith
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: