title: Icefaces outputresource return error 500 until project rebuild
body: <p>When i try to use <strong>ice:outputResource</strong> to download file from server (Liferay jsf2.0), i meet some strange trouble.</p>
  
  <p>With the same code, and page, and file, but outputresource will throw error code 500 until i rebuild my project, after rebuild my file can be downloaded.</p>
  
  <p>My scene is(i'm sure that path and file existed):</p>
  
  <blockquote>
    <p>User upload file A (store file in temp) - downloaded ok</p>
    
    <p>User save action (move file to resource folder) </p>
    
    <p>User edit form (reload file A from resource folder) - download fail (throw error 500)</p>
    
    <p>rebuild code, then upload another file B (same as A)</p>
    
    <p>User edit form (reload A and B) - download A OK but download B fail</p>
  </blockquote>
  
  <p>I put resource init code inside (Hibernate)model to avoid loop:</p>
  
  <pre><code>@Transient
      private Resource ksf_resource;
  
      public Resource getKsf_resource() {
          if(ksf_resource == null){
              try{                    
                  ksf_resource = new CCHCResource("/"+path + "/" , ksf_realname);
                  _log.info("path {}, file {}", path, ksf_realname);
                  }
  
              }catch(Exception ex){
                  //file not found or server error
                  _log.warn("File not found!");
                  ksf_resource = null;
              }
          }
          return ksf_resource;
      }
  </code></pre>
  
  <p>resouce code</p>
  
  <pre><code>public class CCHCResource implements Resource, Serializable {
  
      private static final long serialVersionUID = -639586497927876085L;
  
  
      private String path;
      private String resourceName;
      private InputStream inputStream;
      private final Date lastModified;
  
      public CCHCResource(String path, String resourceName) {
          this.path = path;
          this.resourceName = resourceName;
          this.lastModified= new Date();
      }
  
      @Override
      public InputStream open() throws IOException {
          InputStream stream = FacesContext.getCurrentInstance()
                  .getExternalContext().getResourceAsStream(path + resourceName);
  //      System.out.println("get resource: " + path + resourceName);
          byte[] byteArray = toByteArray(stream);
          inputStream = new ByteArrayInputStream(byteArray);
          return inputStream;
      }
  
      public static byte[] toByteArray(InputStream input) throws IOException {
          ByteArrayOutputStream output = new ByteArrayOutputStream();
          byte[] buf = new byte[4096];
          int len = 0;
          while ((len = input.read(buf)) &gt; -1) output.write(buf, 0, len);
          return output.toByteArray();
      }
  
      @Override
      public String calculateDigest() {
         return resourceName;
      }
  
      @Override
      public void withOptions(Options arg0) throws IOException {
      }
  
      @Override
      public Date lastModified() {
          return lastModified;
      }
  }
  </code></pre>
  
  <p>xhtml</p>
  
  <pre><code>&lt;ice:outputResource
      image="#{resource['images:isoDownload']}"       
      resource="#{file.ksf_resource}"
      attachment="true"
      fileName="#{file.ksf_displayname}"
      type="application/text"
      label="#{itemtp.ksf_displayname}"/&gt;
  </code></pre>