title: Log all JVM file access attempts
body: <p>On a platform that doesn't support any useful logging facility like <code>strace</code> or <code>dtrace</code>, I'm looking to effectively do something like this:</p>
  
  <p><code>strace -eopen -Ff java Foo 2&gt;&amp;1 | grep -i open | grep someFile.xml</code></p>
  
  <p><strong>But I can't, because I can't use strace, or any similar utility on this platform.</strong></p>
  
  <p>What the above <code>strace</code> command does (on Linux, <strong>which is not the platform I'm using in this case</strong>) is it logs each time the process (regardless of the location or nature of the code) attempts to call the <code>open</code> syscall on a file whose absolute path contains <code>someFile.xml</code>. <strong>Critically</strong> to my use case, the <code>strace</code> tool would tell me the full argument passed to the <code>open</code> call, which includes the <em>absolute path</em> to the file attempting to be opened, and a return value (whether the call succeeded or not).</p>
  
  <p>I would like to do this from Java itself. Is there any way to do this without using OS facilities?</p>
  
  <p>I'm fine with not trapping "native" code that might try to access the path, if that's not possible, e.g. libraries invoked via JNA/JNI. As long as I can trap whenever <code>java.io</code> or <code>javax.nio</code> classes attempt to open a file (basically the pure Java APIs for general purpose file access) I'm fine with that.</p>
  
  <p>I can't trap <code>FileNotFoundException</code> or anything because the code appears to be catching a <code>FileNotFoundException</code> and re-throwing it with a custom runtime exception that basically says "I can't find this file!" </p>
  
  <p>The problem is, I don't know <strong>where</strong> that file is supposed to go so the code can find it, in the filesystem tree. The code itself doesn't provide any verbose options or any way to get it to tell me what <em>absolute path</em> it's trying to access that it can't find. </p>
  
  <p>Also, using a debugger isn't convenient (if even possible) on the platform I'm running. </p>
  
  <p>I can't say what platform I'm using, but I <em>can</em> say that the JVM is an IBM JDK that passes Oracle's <a href="https://en.wikipedia.org/wiki/Technology_Compatibility_Kit" rel="nofollow noreferrer">TCK</a> for Java SE 7 and  Java EE 6, so anything that is part of the standards should work, and even some things that are specific to Sun/Oracle Hotspot JVM might also coincidentally be supported (I'd want to try them at least).</p>
  
  <p>--</p>
  
  <p>The pure Java answer by itself is valuable to me. However, I also have this same exact question but for <em>Jython</em> code (Python code running on the same JVM as above) if it would differ at all from pure Java.</p>