title: Debugging Java process using IntelliJ - connects to socket but not to target VM
body: <p>Now resolved - see end of question.</p>
  
  <p>I am attempting to debug a Java process with IntelliJ Community Edition's debugger.  The socket is listening - but when I try to connect the debug process shows the following
  'Connecting to the target VM, address: ':8003', transport: 'socket'
  It never makes the connection to the VM and I cannot debug.</p>
  
  <p>I have moved to a Windows 7 64 bit PC - on my old XP machine and could connect and debug this Java process (it's an app I build and maintain).</p>
  
  <p>It does not fail with the standard "Connection refused: Connect" error that you would get if no process was there to connect to.  Netstat also shows the port is listening when the app is running.</p>
  
  <p>TCP    0.0.0.0:8003           :0         LISTENING</p>
  
  <p>Debug args for the app
  -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8003
  -Xdebug</p>
  
  <p>If I attempt to run the debug session from IntelliJ on a remote machine, I can connect to the process running on my local machine, and debug.
  If I run the Java app on a remote machine, and use IntelliJ on my local machine, I can debug.
  It is only if I run and debug on the same machine that it fails - unfortunately this is what I need to do almost all the time.</p>
  
  <p>The only similar issues I have found are from 2004, to do with file paths with spaces, and were NetBeans, not IntelliJ.  I have rebuilt and rerun my app ensuring no spaces or underscores in the path, no joy.</p>
  
  <p>My intelliJ debug settings are to debug my local machine on socket, attach mode port 8003 - sorry as a new user I can't attach an image.</p>
  
  <p>Other things I have attempted:</p>
  
  <ul><li>Changing JRE versions</li>
  <li>Debugging using shared memory rather than socket transport</li>
  <li>I have not re-installed IntelliJ - I am using the same build as my fellow devs (10.5 IC 107-105) who don't have this problem.</li>
  <li>Changing the port the debugging process listens on (from 8003 to various other, unused according to netstat)</li>
  <li>I have tried using PC name, IP Address and 'localhost' to refer to the PC in the debug settings.</li></ul>
  
  <p>Stuck.  Any help much appreciated.<br>
  Thanks
  Steve</p>
  
  <p>Resolved</p>
  
  <p>Well, a day of failing to solve then I find the answer 20 mins after posting.  An invalid JNI signature character, only picked up when debugging.  Solved by adding this arg when debugging.</p>
  
  <p>-Dcom.sun.xml.bind.v2.bytecode.ClassTailor.noOptimize=true</p>
  
  <p><a href="http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6547438" rel="nofollow">http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6547438</a></p>
  
  <p>Thanks for the assistance.  Still don't know why it would work when debugging remotely but not locally before.</p>