Hi,

In our CI server I can see an occasional NPE:

Caused by: java.lang.NullPointerException: Cannot invoke
"java.util.Optional.isPresent()" because "repeatableMethod" is null
        at 
org.apache.webbeans.portable.AbstractAnnotated.buildRepeatableAnnotations(AbstractAnnotated.java:107)
        at 
org.apache.webbeans.portable.AbstractAnnotated.setAnnotations(AbstractAnnotated.java:166)
        at 
org.apache.webbeans.portable.AnnotatedTypeImpl.<init>(AnnotatedTypeImpl.java:76)
        at 
org.apache.webbeans.portable.AnnotatedElementFactory.newAnnotatedType(AnnotatedElementFactory.java:183)


(It's a test that spans some threads and persists some concurrent data).


It happens once a day at most, and I think it happens lately since I
upgraded to 2.0.16 or 17 (I have no idea why because this hasn't
changed in a while, I can't confirm this)


I've been unable to reproduce it locally neither.


The thing is that looking at AnnotationManager.java:


public Optional<Method> getRepeatableMethod(Class<?> type)
{
    if (repeatableMethodCheckedTypes.contains(type))
    {
        return repeatableMethodCache.get(type);
    }

    Optional<Method> method =
Optional.ofNullable(resolveRepeatableMethod(type));

    repeatableMethodCheckedTypes.add(type);
    repeatableMethodCache.put(type, method); // don't put null here!

    return method;
}


The repeatableMethodCheckedTypes can have the value and the
repeatableMethodCache empty at the same time, which I guess is what's
happening here.


A solution can be to synchronize the add and put, or the
repeatableMethodCheckedTypes can be removed (it's not used anywhere
else, I guess it's there for performance reasons?)

WDYT?

Reply via email to