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

Assert keyword position in constructors

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P4 P4
    • None
    • 1.4.2
    • specification
    • x86
    • windows_nt

      Name: rmT116609 Date: 08/28/2003


      A DESCRIPTION OF THE REQUEST :
      You cannot make an assertion on constructor parameters before you call this(...) or super(...). E.G.:

      public Class(int value)
      {
        // Intended, but does not work
        assert value < 100 : "value < 100";

        super();

        // Possible, but too late
        assert value < 100 : "value < 100";

        ....
      }


      JUSTIFICATION :
      It must be possible to check parameters before calling super() or this(). Otherwise false parameters would not be checked at the right time and debugging gets more complicated.

      EXPECTED VERSUS ACTUAL BEHAVIOR :
      EXPECTED -
      See above in the example
      ACTUAL -
      See above in the example

      ---------- BEGIN SOURCE ----------
      class MyClass
      {

        public MyClass(int value)
        {
          // Intended, but not compilable
          assert value < 100 : "value < 100";

          super();
        }

      }

      ---------- END SOURCE ----------
      (Incident Review ID: 200127)
      ======================================================================

            abuckley Alex Buckley
            rmandalasunw Ranjith Mandala (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: