deltaspike-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Lars-Fredrik Smedberg <itsme...@gmail.com>
Subject Question on ContextUtils
Date Thu, 26 Mar 2015 16:45:53 GMT
Hi

Curious, I saw the following in the ContextUtils sourcecode when I was
looking for some ideas to solve a problem....

    public static boolean isContextActive(Class<? extends Annotation>
scopeAnnotationClass, BeanManager beanManager)
    {
        try
        {
            if (beanManager.getContext(scopeAnnotationClass) == null
                    ||
!beanManager.getContext(scopeAnnotationClass).isActive())
            {
                return false;
            }
        }
        catch (ContextNotActiveException e)
        {
            return false;
        }

        return true;
    }

When I looked at the documentation for BeanManager I saw that getContext
always returns a Context or throw a ContextNotActiveException (amongst
other exceptions), so the null check should not be needed or?

The documenation also mention that the getContext method always return an
active context...

Is the code there to solve some compatibility issues or for other
historical reasons or should it read (or similar):

    public static boolean isContextActive(Class<? extends Annotation>
scopeAnnotationClass, BeanManager beanManager)
    {
        try
        {
    beanManager.getContext(scopeAnnotationClass);
    return true;
        }
        catch (ContextNotActiveException e)
        {
            return false;
        }
    }

Regards
LF

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message