Error: Could not initialize class sun.nio.fs.UnixCopyFile

I have a page that used to successfully upload an image file, and now does not.

I am getting the following error:
error: Could not initialize class sun.nio.fs.UnixCopyFile

Code is:

<cfset dir_upload = "/home/mysitefolder/public_html/temp" >
<cfparam name="form.fileUpload" default="">

<cfif len(trim(form.fileUpload))>	
	<cftry>
        <cffile action="upload"
        fileField="fileUpload"
        destination="#dir_upload#" 
        nameconflict="overwrite" >
        
		<cfscript> 
        	fileSetAccessMode("#dir_upload#/#File.ServerFileName#.#File.ServerFileExt#", "644"); 
        </cfscript> 
        
        <p>View it here: <cfoutput><a href="/temp/#File.ServerFileName#.#File.ServerFileExt#" target="_blank" >#File.ServerFileName#.#File.ServerFileExt#</a></cfoutput></p>
      
	   	<cfcatch type="any" >
        	<cfoutput>error: #cfcatch.Message# #cfcatch.Detail#</cfoutput>
        </cfcatch>
    </cftry>
  
  
</cfif>
<b>Upload</b>
<form enctype="multipart/form-data" method="post">
  <input type="file" name="fileUpload" /><br />
  <input type="submit" value="Upload File" />
</form>

Don’t forget to tell us about your stack!

OS: Centos 7
Java Version: openjdk 11.0.8 2020-07-14 LTS
Tomcat Version: tomcat 9.0.20.0
Lucee Version: Lucee 5.3.7.47

please share the java stacktrace

lucee.runtime.exp.NativeException: Could not initialize class sun.nio.fs.UnixCopyFile at java.base/sun.nio.fs.UnixFileSystemProvider.copy(UnixFileSystemProvider.java:258) at java.base/java.nio.file.Files.copy(Files.java:1294) at lucee.commons.io.res.type.file.FileResource.copyTo(FileResource.java:102) at lucee.commons.io.IOUtil.copy(IOUtil.java:126) at lucee.runtime.tag.FileTag._actionUpload(FileTag.java:988) at lucee.runtime.tag.FileTag.actionUpload(FileTag.java:831) at lucee.runtime.tag.FileTag.doStartTag(FileTag.java:412) at myuploadfile_cfm$cf$2x.call(/myuploadfile.cfm:13) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:945) at lucee.runtime.PageContextImpl._doInclude(PageContextImpl.java:837) at lucee.runtime.listener.ModernAppListener._onRequest(ModernAppListener.java:216) at lucee.runtime.listener.MixedAppListener.onRequest(MixedAppListener.java:42) at lucee.runtime.PageContextImpl.execute(PageContextImpl.java:2416) at lucee.runtime.PageContextImpl._execute(PageContextImpl.java:2406) at lucee.runtime.PageContextImpl.executeCFML(PageContextImpl.java:2381) at lucee.runtime.engine.Request.exe(Request.java:43) at lucee.runtime.engine.CFMLEngineImpl._service(CFMLEngineImpl.java:1170) at lucee.runtime.engine.CFMLEngineImpl.serviceCFML(CFMLEngineImpl.java:1116) at lucee.loader.engine.CFMLEngineWrapper.serviceCFML(CFMLEngineWrapper.java:97) at lucee.loader.servlet.CFMLServlet.service(CFMLServlet.java:51) at javax.servlet.http.HttpServlet.service(HttpServlet.java:741) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:200) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:139) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:408) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1839) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.base/java.lang.Thread.run(Thread.java:834) Caused by: java.lang.NoClassDefFoundError: Could not initialize class sun.nio.fs.UnixCopyFile … 42 more

What I can quickly get from googling around is the following. Please excuse if you’ve already done that. It’s just the first steps I’d do in your case:

  • Is the directory you are uploading the file existent? If not then create it, and make sure when copying no directory creation has to be envolved.
  • Also check if Tomcat has write permission to the folder you’re uploading the file.
1 Like

Thanks Andreas, after all that, it appears that a permissions fix resolved this issue. Not sure how those permissions had changed, but glad to have this solved.

Thanks!

2 Likes

I have filed a bug to improve the error message / feedback when this happens, it’s way too cryptic

https://luceeserver.atlassian.net/browse/LDEV-3220

1 Like