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

lint warning for exception in initializer

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Rejected
    • P4
    • None
    • 7
    • tools
    • generic
    • generic

    Description

      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.

      Attachments

        Issue Links

          Activity

            People

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

              Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: