There was a problem while creating the temporary file

  • Updated

Issue

One of following exceptions are encountered when attempting to startup my application with the Contrast Java Agent. 

java.lang.IllegalStateException: There was a problem while creating the temporary file
at com.contrastsecurity.agent.ContrastLoaderAgent.getTempFileFromInputStream(ContrastLoaderAgent.java:207)
at com.contrastsecurity.agent.ContrastLoaderAgent.getJarFileFromInputStream(ContrastLoaderAgent.java:178)
at com.contrastsecurity.agent.ContrastLoaderAgent.getAgentCoreJar(ContrastLoaderAgent.java:88)
at com.contrastsecurity.agent.injection.ClassInjector.inject(ClassInjector.java:37)
at com.contrastsecurity.agent.ContrastLoaderAgent.premain(ContrastLoaderAgent.java:72)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.io.IOException: Permission denied
at java.io.UnixFileSystem.createFileExclusively(Native Method)
at java.io.File.createTempFile(File.java:2024)
at java.io.File.createTempFile(File.java:2070)
at com.contrastsecurity.agent.ContrastLoaderAgent.getTempFileFromInputStream(ContrastLoaderAgent.java:197)
... 10 more
Unexpected error during Contrast Agent initialization. Continuing application startup without Contrast Agent....
Exception in thread "main" java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.NoClassDefFoundError: com/contrastsecurity/agent/core/ContrastAgent
at com.contrastsecurity.agent.ContrastLoaderAgent.premain(ContrastLoaderAgent.java:79)
... 6 more
Caused by: java.lang.ClassNotFoundException: com.contrastsecurity.agent.core.ContrastAgent
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 7 more

or

java.lang.IllegalStateException: There was a problem while creating the temporary file
        at com.contrastsecurity.agent.ContrastLoaderAgent.getTempFileFromInputStream(ContrastLoaderAgent.java:207)
        at com.contrastsecurity.agent.ContrastLoaderAgent.getJarFileFromInputStream(ContrastLoaderAgent.java:178)
        at com.contrastsecurity.agent.ContrastLoaderAgent.getAgentCoreJar(ContrastLoaderAgent.java:88)
        at com.contrastsecurity.agent.injection.ClassInjector.inject(ClassInjector.java:37)
        at com.contrastsecurity.agent.ContrastLoaderAgent.premain(ContrastLoaderAgent.java:72)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.io.IOException: No such file or directory
        at java.io.UnixFileSystem.createFileExclusively(Native Method)
        at java.io.File.createTempFile(File.java:2024)
        at java.io.File.createTempFile(File.java:2070)
        at com.contrastsecurity.agent.ContrastLoaderAgent.getTempFileFromInputStream(ContrastLoaderAgent.java:197)
        ... 10 more
Unexpected error during Contrast Agent initialization. Continuing application startup without Contrast Agent....
Exception in thread "main" java.lang.reflect.InvocationTargetException
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
        at java.lang.reflect.Method.invoke(Method.java:498)
        at sun.instrument.InstrumentationImpl.loadClassAndStartAgent(InstrumentationImpl.java:386)
        at sun.instrument.InstrumentationImpl.loadClassAndCallPremain(InstrumentationImpl.java:401)
Caused by: java.lang.NoClassDefFoundError: com/contrastsecurity/agent/core/ContrastAgent
        at com.contrastsecurity.agent.ContrastLoaderAgent.premain(ContrastLoaderAgent.java:79)
        ... 6 more
Caused by: java.lang.ClassNotFoundException: com.contrastsecurity.agent.core.ContrastAgent
        at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
        at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
        ... 7 more
FATAL ERROR in native method: processing of -javaagent failed

 

Cause

The Contrast Java agent requires a small amount of space to use as a working directories. During startup:

  • The Java agent will extract a few jar files to the java tmp directory ( Versions < 3.7.9.17038 )
  • The Java agent will create/write files to it's working directory

Resolution

To avoid these type of exceptions, pre-create these folders and set permissions so the application server has full access to them.  These directories can be controlled with the following JVM properties.

  • -Dcontrast.dir=/path to folder/       Location of Contrast "workspace"
  • -Djava.io.tmpdir=/path to folder/    Location of java tmp directory

 

Was this article helpful?

0 out of 0 found this helpful

Have more questions? Submit a request