Search code examples
jsfmojarrafacescontext

why exist initContextServletContext in JSF Mojarra 2.2 FacesContext.java


private static ConcurrentHashMap initContextServletContext = new ConcurrentHashMap(2);

field is private, but never used in FacesContext class. Is there a reason to exist?


Solution

  • It's accessed by reflection in Mojarra-specific com.sun.faces.config.InitFacesContext implementation which is only used during container initialization (line numbers match Mojarra 2.2.11):

    675    static Map getThreadInitContextMap() {
    676        ConcurrentHashMap threadInitContext = null;
    677        try {
    678            Field threadMap = FacesContext.class.getDeclaredField("threadInitContext");
    679            threadMap.setAccessible(true);
    680            threadInitContext = (ConcurrentHashMap)threadMap.get(null);
    681        } catch (Exception e) {
    682            if (LOGGER.isLoggable(Level.FINEST)) {
    683                LOGGER.log(Level.FINEST, "Unable to get (thread, init context) map", e);
    684            }
    685        }
    686        return threadInitContext;
    687    }
    

    See also: