geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Romain Manni-Bucau <rmannibu...@gmail.com>
Subject [spec / cdi 2] bad impl for javax.enterprise.inject.se.SeContainerInitializer#newInstance?
Date Sat, 01 Jul 2017 12:29:29 GMT
Hi guys,

just saw how javax.enterprise.inject.se.SeContainerInitializer#newInstance
has been implemented. I'm not sure it was based on the ref implementation
but - ignoring for now the OSGi issues - I don't think it works:

long exactSize = serviceLoader.spliterator().getExactSizeIfKnown();
if(exactSize == 0)
{
    throw new IllegalStateException("No valid implementation of
SeContainerInitializer found via ServiceLoader");
}
else if(exactSize > 1)
{
    throw new IllegalStateException("Multiple implementations
("+exactSize+") of SeContainerInitializer found via ServiceLoader");
}
return serviceLoader.iterator().next();


exactSize will be -1 since the splititerator doesnt have the size as a
characteristic so we'll always be not deterministic which seems not
intended.

Am I missing anything?

Do we want to use the old instance = next(); if (hasNext()) fail(); pattern?

Romain Manni-Bucau
@rmannibucau <https://twitter.com/rmannibucau> |  Blog
<https://blog-rmannibucau.rhcloud.com> | Old Blog
<http://rmannibucau.wordpress.com> | Github <https://github.com/rmannibucau> |
LinkedIn <https://www.linkedin.com/in/rmannibucau> | JavaEE Factory
<https://javaeefactory-rmannibucau.rhcloud.com>

Mime
View raw message