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

warnings desired for almost certain errors

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 1.1.1, 1.3.1, 1.4.0, 1.4.1, 1.4.2
    • tools

      Please have javac produce (optional!) warnings for the following
      situations which are almost certainly programmer errors, or very
      poor style at best:

      overriding equals() but not hashCode() or vice versa
      a finally clause that cannot complete normally
      a member type or field that is hidden in a subclass
      selecting a static member from an object value

      ================
      I recently had a surprising bug in some of my code which might inform
      the addition of a compiler warning (possibly under a "-fullwarn" option or
      similar).

         public class Foo {
           public void Foo() {
                  ^^^^

      I accidentally added a "void" before the constructor's name, which turned the
      constructor into a method, causing the object to be uninitialized.

      ==================
      Subject:
                Proposed Lint Rules
          Date:
                Mon, 28 Jan 2002 16:36:22 -0800
         From:
                <###@###.###>
            To:
                <###@###.###>




         Not all of these are practical or advisible. Some important ones may be missing. I have not looked at the rules for C's lint, many of which may be applicable here. All of that said, this is a reasonable starting point.
       

      Proposed Lint Warnings

      Public or protected static method or field hidden.

      More generally, anything hidden

      Static method invoked via instance

      return or throw within finally

      "Potentially ambiguous" overloading
          Same number of args; for each arg, one is subtype of other. (I don't
          think that we can do this one: it would fire too often.)

      Mixed type comparison.
        (<, ==, >, <=, >=, where primitive operands are of different type).

      Public non-final field in public class.

      Constructor or method whose signature differs from another only in parameter
      order

      Use of String(String) or Boolean(boolean).

      Constructor or pseudoconstructor (clone, readObject) invokes overridable
      method in same class.

      Class consisting entirely of static methods with default constructor (AKA
      unintentionally instantialble class).

      Any use of a finalizer
          (I know this one is rather audacious)

      equals overridden but not hashCode

      equals(ThisType) provided but not equals(Object)

      Object's toString implementation not overridden in a public class.

      Concrete class implements Cloneable but does not override clone

      clone method in an extendable public class does not invoke super.clone

      public static final non-zero length array.

      Interface consisting solely of (one or more) static fields.

      nonstatic member class whose enclosing reference is never used (should be
      static).

      Concrete collection class as input parameter

      Array-returning method returns null

      Method declared to throw unchecked exception

      These three are already covered by doccheck, and don't belong in compiler:
         Public or protected member missing doc comment
         Parameter of public or protected method missing doc comment
         Declared exception of public or protected method missing doc comment

      Broken idioms:
      Math.abs( <instance of java.util.Random>.nextInt()) % <int expression>
      Math.abs( <instance of java.util.Random>.nextInt() % <int expression>)
         Should be replaced by Random.nextInt(int)

      Switch statement with one or more fall-throughs

      Class name begins with something other than an uppercase letter

      Varibale name other than a static final begins with something other than a
      lowercase letter.

      Method name begins with something other than a lowercase letter

      package name contains capital letters

      Empty catch clause.
         (If the catch clause contains so much as a comment, this warning should not
         be emitted.)

      Object.wait invoked outside of a loop

      Any use of Thread.yield

      Inner class implements Serializable

      Class that implements Serializable does not declare serialVersionUID

      Interface declares serialVersionUID

      =====================================================
      A class inherits a type with the same name as the class:

          package p;
          class B {
              static class A {}
          }
          class A extends B {
              // the constructor for p.A takes a
              // parameter of type p.B.A
              A(A x) {}
          }
      ###@###.### 10/27/04 17:27 GMT

            jlahoda Jan Lahoda
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: