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

Mutually recursive constructors could be flagged as warning or error

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P5
    • Resolution: Duplicate
    • Affects Version/s: 1.1.2
    • Fix Version/s: None
    • Component/s: tools
    • Subcomponent:
    • CPU:
      sparc
    • OS:
      solaris_2.5.1

      Description

      If a class has two constructors that each call the other with this(...),
      this could be called an warning, because it is never possible for this to
      not throw an exception. (It will end with StackOverflowError, OutOfMemoryError, or if the argument evaluations throw any exception).

      While it may be reasonable to allow this for the side effects the argument evaluations could have, I believe a warning would make much more sense than
      saying nothing.


      Example code:

      public class ConCir {

        public ConCir(int a, double d){
      this(a,d,0);
        }

        public ConCir(int a, double d, int b){
      this(a,d);
        }

        public static void main(String[] args){
          new ConCir(0,0.0);
        }

      }

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              wmaddoxsunw William Maddox (Inactive)
              Reporter:
              duke J. Duke (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: