title: Primefaces autocomplete null pointer exception
body: <p>I searched in old questions but I found nothing useful; I googled also a lot
  I have a simple primefaces autocomplete so defined:</p>
  
  <pre><code>&lt;p:autoComplete id="comNascita" 
  value="#{gestioneDomandaResFormBean.datiDomanda.datiAnagrafici.comuneNascita}" 
  required="true" 
  converter="deComuneConverter"
  forceSelection="true" 
  var="comune" 
  itemLabel="#{comune.descrizione}" 
  label="#{ui['ui.res.creaDomanda.crea.domanda.form.comuneNascita']}"
  itemValue="#{comune}" 
  emptyMessage="Nullo"
  completeMethod="#{decodificheBeanSvil.completeComuni}" 
  size="55" 
  minQueryLength="2"
  styleClass="w100" 
  cache="true" 
  widgetVar="comNascitaWV" 
  maxResults="10"/&gt;
  </code></pre>
  
  <p>This is my converter:</p>
  
  <pre><code>@FacesConverter("deComuneConverter")
  public class DeComuneConverter implements Converter 
  {
  
      protected final Logger logger = LoggerFactory.getLogger(this.getClass());
      private DeComuneEJB deComuneManager = null;
      @Override
      public Object getAsObject(FacesContext context, UIComponent component, String value) 
      {
          if (value == null || value.trim().equals("")) 
          {
              if( logger.isDebugEnabled() )
              {
                  logger.debug("Metodo getAsObject. Passato un value nullo o vuoto &lt;"+value+"&gt;. Restituisco null");
              }
              return null;
          } 
          else 
          {
              DeComune deComune = null;
              try 
              {
                  deComune = deComuneManager.findById(value);
              } 
              catch (Exception e) 
              {
                  if( logger.isWarnEnabled() )
                  {
  
                      logger.warn("Errore nella converter dei comuni; "+e.getMessage(), e);
                  }
              }
              return deComune;
          }
      }
  
      @Override
      public String getAsString(FacesContext context, UIComponent component, Object value) {
          if (value == null ||  (value instanceof String &amp;&amp; ((String)value).trim().equals(""))) 
          {
              if( logger.isDebugEnabled() )
              {
                  logger.debug("Metodo getAsString. Passato un value nullo o vuoto &lt;"+value+"&gt;; restituisco stringa vuota"); 
              }
              return "";
          } else {
              return String.valueOf(((DeComune) value).getCodCom());
          }
      }
      @PostConstruct
      public void initialize() throws Exception
      {
          InitialContext ic = null;
          try
          {
              ic = new InitialContext();
              deComuneManager = (DeComuneEJB) ic.lookup("java:module/"+DeComuneEJB.class.getSimpleName());
          }
          catch (Exception e) {
              if( logger.isErrorEnabled() )
              {
                  logger.error("Errore nella ricerca JNDI dell'EJB per i comuni", e);
              }
              throw e;
          }
          finally 
          {
              if( ic != null )
              {
                  ic.close();
              }
          }
      }
  }
  </code></pre>
  
  <p>This is my bean with the complete method:</p>
  
  <pre><code>@ManagedBean(name = "decodificheBeanSvil")
  @ApplicationScoped
  public class DecodificheBeanSvil implements Serializable {
  
      private static final long serialVersionUID = -5773268651349037154L;
  
      protected static final Log log = LogFactory.getLog(DecodificheBeanSvil.class);
  
      protected Date currentDate;
  
      @PostConstruct
      protected void postConstruct() {
          currentDate = new Date();
      }
      public GenereEnum[] getGenereList() {
          return GenereEnum.values();
      }
      public List&lt;DeComune&gt; completeComuni(String startsWith)
      {
          List&lt;DeComune&gt; result = new ArrayList&lt;DeComune&gt;();
          Map&lt;String, DeComune&gt; comuniFake = FakeUtils.getComuniEr();
          Iterator&lt;String&gt; chiaviIterator = comuniFake.keySet().iterator();
          while (chiaviIterator.hasNext()) {
              String chiave = chiaviIterator.next();
              if( chiave.startsWith(startsWith.toLowerCase()) )
              {
                  result.add(comuniFake.get(chiave));
              }
          }
          return result;
      }
  }
  </code></pre>
  
  <p>This is my DeComune POJO:</p>
  
  <pre><code>public class DeComune implements Serializable, Comparable&lt;DeComune&gt; {
  
      private static final long serialVersionUID = -6250752442360948142L;
      private String codCom;
      private String descrizione;
      private String cap;
  
      public DeComune() {
          super();
      }
  
      public DeComune(String codCom, String descrizione, String cap) {
          super();
          this.codCom = codCom;
          this.descrizione = descrizione;
          this.cap = cap;
      }
  
      public String getCodCom() {
          return codCom;
      }
  
      public void setCodCom(String codCom) {
          this.codCom = codCom;
      }
  
      public String getDescrizione() {
          return descrizione;
      }
  
      public void setDescrizione(String descrizione) {
          this.descrizione = descrizione;
      }
  
      public String getCap() {
          return cap;
      }
  
      public void setCap(String cap) {
          this.cap = cap;
      }
  
      @Override
      public int compareTo(DeComune o) {
          return this.descrizione.compareTo(o.getDescrizione());
      }
  }
  </code></pre>
  
  <p>This is my FakeUtils</p>
  
  <pre><code>public abstract class FakeUtils {
  
      private static List&lt;String&gt; elencoComuniFake;
      private static Map&lt;String, DeComune&gt; elencoDeComuneFake;
      public static List&lt;DeComune&gt; fakeComuni()
      {
          elencoDeComuneFake = getMap();
          List&lt;DeComune&gt; result = new ArrayList&lt;DeComune&gt;(elencoComuniFake.size());
          result.addAll(elencoDeComuneFake.values());
          return result;
      }
      public static Map&lt;String, DeComune&gt; getComuniEr()
      {
          if( elencoDeComuneFake == null )
          {
              elencoDeComuneFake = getMap();
          }
          return elencoDeComuneFake;
      }
      public static DeComune getById( String id )
      {
          if( elencoDeComuneFake == null )
          {
              elencoDeComuneFake = getMap();
          }
          return elencoDeComuneFake.get(id.trim().toLowerCase());
      }
      private static Map&lt;String, DeComune&gt; getMap()
      {
          if( elencoDeComuneFake == null )
          {
              elencoComuniFake = elencoComuniFake();
  
              elencoDeComuneFake = new HashMap&lt;String, DeComune&gt;(elencoComuniFake.size());
              for (String nomeComune : elencoComuniFake) 
              {
                  elencoDeComuneFake.put(nomeComune.trim().toLowerCase(), new DeComune(nomeComune, nomeComune, nomeComune));
              }
          }
          return elencoDeComuneFake;
      }
      private static List&lt;String&gt; elencoComuniFake()
      {
          if( elencoComuniFake == null )
          {
              elencoComuniFake = new ArrayList&lt;String&gt;();
              elencoComuniFake.add("Agazzano");
              elencoComuniFake.add("Albareto");
          }
          return elencoComuniFake;
      }
  
  }
  </code></pre>
  
  <p>When I type something in the autocomplet field I get the following exception:</p>
  
  <pre><code>11:33:07,235 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost/127.0.0.1:20000-3) Error Rendering View[/secure/domanda/_form/creaDomanda.xhtml]: javax.faces.event.AbortProcessingException: java.lang.NullPointerException
      at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:303) [primefaces-6.0.jar:6.0]
      at org.primefaces.context.PrimePartialResponseWriter.startUpdate(PrimePartialResponseWriter.java:142) [primefaces-6.0.jar:6.0]
      at org.omnifaces.context.OmniPartialViewContext$OmniPartialResponseWriter.startUpdate(OmniPartialViewContext.java:300) [omnifaces-2.0.jar:2.0]
      at com.sun.faces.context.PartialViewContextImpl$PhaseAwareVisitCallback.visit(PartialViewContextImpl.java:541) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at com.sun.faces.component.visit.PartialVisitContext.invokeVisitCallback(PartialVisitContext.java:183) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1611) [jsf-api-2.1.29-03.jar:2.1]
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1622) [jsf-api-2.1.29-03.jar:2.1]
      at javax.faces.component.UIComponent.visitTree(UIComponent.java:1622) [jsf-api-2.1.29-03.jar:2.1]
      at com.sun.faces.context.PartialViewContextImpl.processComponents(PartialViewContextImpl.java:383) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at com.sun.faces.context.PartialViewContextImpl.processPartial(PartialViewContextImpl.java:302) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at org.primefaces.context.PrimePartialViewContext.processPartial(PrimePartialViewContext.java:57) [primefaces-6.0.jar:6.0]
      at javax.faces.context.PartialViewContextWrapper.processPartial(PartialViewContextWrapper.java:183) [jsf-api-2.1.29-03.jar:2.1]
      at javax.faces.component.UIViewRoot.encodeChildren(UIViewRoot.java:973) [jsf-api-2.1.29-03.jar:2.1]
      at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1778) [jsf-api-2.1.29-03.jar:2.1]
      at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:426) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at com.ocpsoft.pretty.faces.application.PrettyViewHandler.renderView(PrettyViewHandler.java:163) [prettyfaces-jsf2-3.3.3.jar:]
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jsf-api-2.1.29-03.jar:2.1]
      at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:286) [jsf-api-2.1.29-03.jar:2.1]
      at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.29-03.jar:2.1.29-03]
      at javax.faces.webapp.FacesServlet.service(FacesServlet.java:604) [jsf-api-2.1.29-03.jar:2.1]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:145) [prettyfaces-jsf2-3.3.3.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:840) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:622) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:560) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:488) [jbossweb-7.0.17.Final.jar:]
      at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:137) [prettyfaces-jsf2-3.3.3.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at it.eng.sil.res.controller.filter.VerificaAccessoFilter.doFilter(VerificaAccessoFilter.java:93) [classes:]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at org.jasig.cas.client.util.HttpServletRequestWrapperFilter.doFilter(HttpServletRequestWrapperFilter.java:75) [cas-client-core-3.2.1.jar:3.2.1]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at org.jasig.cas.client.authentication.AuthenticationFilter.doFilter(AuthenticationFilter.java:107) [cas-client-core-3.2.1.jar:3.2.1]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at org.jasig.cas.client.validation.AbstractTicketValidationFilter.doFilter(AbstractTicketValidationFilter.java:201) [cas-client-core-3.2.1.jar:3.2.1]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at org.jasig.cas.client.session.SingleSignOutFilter.doFilter(SingleSignOutFilter.java:76) [cas-client-core-3.2.1.jar:3.2.1]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at it.eng.sil.res.controller.filter.CharacterEncodingFilter.doFilter(CharacterEncodingFilter.java:95) [classes:]
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.17.Final.jar:]
      at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.3.Final.jar:7.1.3.Final]
      at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:165) [jboss-as-web-7.1.3.Final.jar:7.1.3.Final]
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.17.Final.jar:]
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:372) [jbossweb-7.0.17.Final.jar:]
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.17.Final.jar:]
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.17.Final.jar:]
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.17.Final.jar:]
      at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_67]
  Caused by: java.lang.NullPointerException
      at org.primefaces.util.ResourceUtils.filterStylesheets(ResourceUtils.java:96) [primefaces-6.0.jar:6.0]
      at org.primefaces.context.PrimePartialResponseWriter.startMetadataIfNecessary(PrimePartialResponseWriter.java:287) [primefaces-6.0.jar:6.0]
      ... 64 more
  </code></pre>
  
  <p>I'm stopped here from a couple of hours... Does anybody know what my issue can be?</p>
  
  <p>Thank you</p>