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

Assert keyword position in constructors

    Details

    • Type: Enhancement
    • Status: Closed
    • Priority: P4
    • Resolution: Won't Fix
    • Affects Version/s: 1.4.2
    • Fix Version/s: None
    • Component/s: specification
    • Labels:
    • Subcomponent:
    • CPU:
      x86
    • OS:
      windows_nt

      Description

      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)
      ======================================================================

        Attachments

          Issue Links

            Activity

              People

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

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: