Java.io.IOException seen during startup ("Can't promise read/write on cache dir")

  • Updated

Issue

I see java.io.IOException: Can't promise read/write on cache dir, error when starting up, for example:

[Contrast] Mon Jun 08 15:01:20 CDT 2020 Starting Contrast (build 3.7.3.14727) Pat. 8,458,789 B2
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: com.contrastsecurity.agent.h: Unable to create references to working directories
at com.contrastsecurity.agent.config.o.a(DefaultLogLocationConfigProvider.java:65)
at com.contrastsecurity.agent.config.e.a(ChainedConfigProvider.java:28)
at com.contrastsecurity.agent.config.d$4.b(CachingConfigProvider.java:142)
at com.contrastsecurity.agent.config.d$4.a(CachingConfigProvider.java:140)
at com.contrastsecurity.agent.o.a(ExpiringCacheSupplier.java:57)
at com.contrastsecurity.agent.config.d.a(CachingConfigProvider.java:148)
at com.contrastsecurity.agent.config.e.a(ChainedConfigProvider.java:28)
at com.contrastsecurity.agent.config.g.b(Config.java:572)
at com.contrastsecurity.agent.config.g.a(Config.java:547)
at com.contrastsecurity.agent.config.g.a(Config.java:536)
at com.contrastsecurity.agent.h.d.a(Log4jLoggerInitializer.java:129)
at com.contrastsecurity.agent.h.d.a(Log4jLoggerInitializer.java:96)
at com.contrastsecurity.agent.j.a.b(Log4jInitializationTask.java:34)
at com.contrastsecurity.agent.core.ContrastAgent.startup(ContrastAgent.java:255)
at com.contrastsecurity.agent.core.ContrastAgent.setup(ContrastAgent.java:118)
at com.contrastsecurity.agent.ContrastLoaderAgent.premain(ContrastLoaderAgent.java:95)
... 6 more
Caused by: java.io.IOException: Can't promise read/write on cache dir
at com.contrastsecurity.agent.config.w.c(WorkingDirectories.java:136)
at com.contrastsecurity.agent.config.w.a(WorkingDirectories.java:26)
at com.contrastsecurity.agent.config.o.a(DefaultLogLocationConfigProvider.java:63)
... 21 more

Cause

This means that the agent doesn't have read/write access to the cache directory.

Resolution

By default, the Contrast working directory is located at ${HOME}/.contrast of the user account the application runs under, and requires permissions 755. The cache is a sub-directory of the working directory. If the location of this directory has been modified (for example with the -Dcontrast.agent.contrast_working_dir property), or if the application (and therefore the agent) is running with permissions that prevent the agent the necessary access to its cache, you must modify the permissions to allow this access.

To address the issue, you can ensure that the default Contrast working directory and it's sub-directories have the necessary 755 permissions.

Alternatively, you can add -Dcontrast.agent.contrast_working_dir to point to a directory that the user has ensured access to. This value will override the default Contrast working directory and creates the directory if it does not exist.

More information on configuring the contrast directory can be found in our Java docs.

Was this article helpful?

1 out of 1 found this helpful

Have more questions? Submit a request