commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 25357] New: - Enumeration in Service broken
Date Tue, 09 Dec 2003 12:41:40 GMT
DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG 
RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT
<http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25357>.
ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND 
INSERTED IN THE BUG DATABASE.

http://nagoya.apache.org/bugzilla/show_bug.cgi?id=25357

Enumeration in Service broken

           Summary: Enumeration in Service broken
           Product: Commons
           Version: Nightly Builds
          Platform: Other
        OS/Version: Other
            Status: NEW
          Severity: Normal
          Priority: Other
         Component: Discovery
        AssignedTo: commons-dev@jakarta.apache.org
        ReportedBy: matthew_pocock@yahoo.co.uk


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
  }
};

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message