[
https://issues.apache.org/jira/browse/DISCOVERY-17?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Simone Tripodi updated DISCOVERY-17:
------------------------------------
Description:
I find the current Enumeration behavior broken, but please tell me if I'm
wrong!!!
This is the actual current behavior:
{code}
return new Enumeration<S>() {
private S object = getNextClassInstance();
public boolean hasMoreElements() {
return object != null;
}
public S nextElement() {
if (object == null) {
throw new NoSuchElementException();
}
S obj = object;
object = getNextClassInstance();
return obj;
}
private S getNextClassInstance() {
while (services.hasNext()) {
ResourceClass<S> info = services.nextResourceClass();
try {
return spi.newInstance(info.loadClass());
} catch (Exception e) {
return null;
} catch (UnsatisfiedLinkError ule) {
return null;
} catch (ExceptionInInitializerError eiie) {
return null;
}
}
return null;
}
};
{code}
but shouldn't it be
{code}
return new Enumeration<S>() {
public boolean hasMoreElements() {
return services.hasNext();
}
public S nextElement() {
ResourceClass<S> info = services.nextResourceClass();
try {
return spi.newInstance(info.loadClass());
} catch (Exception e) {
return null;
} catch (UnsatisfiedLinkError ule) {
return null;
} catch (ExceptionInInitializerError eiie) {
return null;
}
}
};
{code}
I think there's no need to comment both codes, please tell me why the first one
should be right :P
was:
I find the current Enumeration behavior broken, but please tell me if I'm
wrong!!!
This is the actual current behavior:
{code}
return new Enumeration<S>() {
private S object = getNextClassInstance();
public boolean hasMoreElements() {
return object != null;
}
public S nextElement() {
if (object == null) {
throw new NoSuchElementException();
}
S obj = object;
object = getNextClassInstance();
return obj;
}
private S getNextClassInstance() {
while (services.hasNext()) {
ResourceClass<S> info = services.nextResourceClass();
try {
return spi.newInstance(info.loadClass());
} catch (Exception e) {
return null;
} catch (UnsatisfiedLinkError ule) {
return null;
} catch (ExceptionInInitializerError eiie) {
return null;
}
}
return null;
}
};
{code}
but shouldn't it be
{code}
return new Enumeration<S>() {
public boolean hasMoreElements() {
return services.hasNext();
}
public S nextElement() {
ResourceClass<S> info = services.nextResourceClass();
try {
return spi.newInstance(info.loadClass());
} catch (Throwable e) {
// TODO log exception
return null;
}
}
};
{code}
I think there's no need to comment both codes, please tell me why the first one
should be right :P
> Enumeration returned by Service.providers has a broken behavior
> ---------------------------------------------------------------
>
> Key: DISCOVERY-17
> URL: https://issues.apache.org/jira/browse/DISCOVERY-17
> Project: Commons Discovery
> Issue Type: Bug
> Affects Versions: 0.5
> Reporter: Simone Tripodi
> Assignee: Simone Tripodi
> Fix For: 0.5
>
> Original Estimate: 20m
> Remaining Estimate: 20m
>
> I find the current Enumeration behavior broken, but please tell me if I'm
> wrong!!!
> This is the actual current behavior:
> {code}
> return new Enumeration<S>() {
> private S object = getNextClassInstance();
> public boolean hasMoreElements() {
> return object != null;
> }
> public S nextElement() {
> if (object == null) {
> throw new NoSuchElementException();
> }
> S obj = object;
> object = getNextClassInstance();
> return obj;
> }
> private S getNextClassInstance() {
> while (services.hasNext()) {
> ResourceClass<S> info = services.nextResourceClass();
> try {
> return spi.newInstance(info.loadClass());
> } catch (Exception e) {
> return null;
> } catch (UnsatisfiedLinkError ule) {
> return null;
> } catch (ExceptionInInitializerError eiie) {
> return null;
> }
> }
> return null;
> }
> };
> {code}
> but shouldn't it be
> {code}
> return new Enumeration<S>() {
> public boolean hasMoreElements() {
> return services.hasNext();
> }
> public S nextElement() {
> ResourceClass<S> info = services.nextResourceClass();
> try {
> return spi.newInstance(info.loadClass());
> } catch (Exception e) {
> return null;
> } catch (UnsatisfiedLinkError ule) {
> return null;
> } catch (ExceptionInInitializerError eiie) {
> return null;
> }
> }
> };
> {code}
> I think there's no need to comment both codes, please tell me why the first
> one should be right :P
--
This message is automatically generated by JIRA.
For more information on JIRA, see: http://www.atlassian.com/software/jira