title: JSP - TransformerFactory.newInstance().newTransformer(xsl) returning null?
body: <p>The java API guarantees that it will never return a null - but for me, it is!</p>
  
  <p><a href="http://download.oracle.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source" rel="nofollow">http://download.oracle.com/javase/6/docs/api/javax/xml/transform/TransformerFactory.html#newTransformer(javax.xml.transform.Source</a>)</p>
  
  <p>Relevant code:</p>
  
  <pre><code>xml = new StreamSource(new URL(mondialURL).openStream());
  xsl = new StreamSource(new File("/REMOVED/countriesnofilter.xsl"));
  result = new StreamResult(new PrintWriter(out));
  
  transformer = TransformerFactory.newInstance().newTransformer(xsl);
  transformer.transform(xml, result);
  </code></pre>
  
  <p>Since xml, xsl and result were made something using new, they -must- contain not null, so it must be transformer that's becoming null. Why is this happening and how can I fix it?</p>
  
  <p>Throws this:</p>
  
  <p>org.apache.jasper.JasperException: Exception in JSP: /dca/ass2/a.jsp:46</p>
  
  <pre><code>43:  result = new StreamResult(new PrintWriter(out));
  44:  
  45:  transformer = TransformerFactory.newInstance().newTransformer(xsl);
  46:  transformer.transform(xml, result);
  47: 
  48: %&gt;
  49:  &lt;INPUT TYPE="SUBMIT" VALUE="Get one country"&gt;
  
  
  Stacktrace:
   org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:451)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:373)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
   sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
   java.security.AccessController.doPrivileged(Native Method)
   javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
   org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
   org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
  root cause
  
  java.lang.NullPointerException
   org.apache.jsp.dca.ass2.a_jsp._jspService(a_jsp.java:104)
   org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:98)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
   org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:331)
   org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:329)
   org.apache.jasper.servlet.JspServlet.service(JspServlet.java:265)
   javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
   sun.reflect.GeneratedMethodAccessor50.invoke(Unknown Source)
   sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
   java.lang.reflect.Method.invoke(Method.java:597)
   org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:244)
   java.security.AccessController.doPrivileged(Native Method)
   javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
   org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:276)
   org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:162)
  </code></pre>
  
  <p>EDIT: It is DEFINITELY the case that the transformer is null somehow. Watch:</p>
  
  <p>org.apache.jasper.JasperException: Exception in JSP: /dca/ass2/a.jsp:49</p>
  
  <pre><code>46:     
  47:     xml.getInputStream();
  48:     xsl.getInputStream();
  49:     transformer.reset();
  50:     
  51:     //transformer.transform(xml, result);
  52: 
  </code></pre>
  
  <p>And it's a null pointer exception again. If it was because xml was null then it would have thrown an NPE at 47.</p>
  
  <p>EDIT2: If I change newTransformer(xsl) to newTransformer() it works, so it's a problem in newTransformer(xsl).</p>