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

need annotation that causes compiler to complain when invoking static methods through instance variables

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Unresolved
    • P4
    • None
    • None
    • tools
    • None

    Description

      I originally filed this as JDK-6177893, repeated here:

      Date: Fri, 08 Oct 2004 16:38:18 -0700
      From: Bill Shannon <###@###.###>

      In JavaMail the Transport class has a static "send" message and a
      non-static "sendMessage" method. A common error is to create
      your own Transport instance and then invoke the send method on
      the instance instead of the sendMessage method.

      I'd like javac to give me a warning when a static method is invoked
      on an instance. Seeing as how javac doesn't produce warnings by
      default, I assume this would be a lint-like warning that you would
      have to explicitly enable.

      I'd also like an annotation that I could apply to a static method
      that made it an error to invoke that method on an instance. Or,
      possibly this would just cause javac to produce this warning by
      default.
      ###@###.### 10/12/04 20:26 GMT

      The -Xlint:static option addresses the first part, but I'd still like the
      annotation that causes this warning (or better yet, failure) by default.
      (The people who make this mistake are not the type of people who
      use -Xlint.)

      The usage error with JavaMail described above still happens very
      frequently.

      Attachments

        Issue Links

          Activity

            People

              jjg Jonathan Gibbons
              bshannon Bill Shannon (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: