Uploaded image for project: 'Commons Discovery'
  1. Commons Discovery
  2. DISCOVERY-3

[discovery] Enumeration in Service broken

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • Nightly Builds
    • 0.5
    • None
    • Operating System: other
      Platform: Other

    • 25357

    Description

      The Enumeration in org.apache.commons.discovery.tools.Service is broken - it
      will only work in the (admittedly common) case where you do:

      while(e.hasMoreElements()) e.nextElement();

      If you repeatedly call nextElement(), you will get the wrong results. In
      particular, this uggly but technically correct code will fail to behave sanely:

      try

      { while(true) e.nextElement(); }

      catch (NoSuchElementException e) {
      }

      The code needs hacking arround to look something more like this:

      return new Enumeration() {
      private Object object = getNextClassInstance();

      public boolean hasMoreElements()

      { return object != null; }

      public Object nextElement() {
      if(object == null)

      { throw new NoSuchElementException(); }

      Object obj = object;
      object = getNextClassInstance();
      return obj;
      }

      private Object getNextClassInstance()

      { // as before }

      };

      Attachments

        Activity

          People

            simone.tripodi Simone Tripodi
            matthew_pocock@yahoo.co.uk matthew_pocock
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: