{"action":"created","issue":{"url":"https://api.github.com/repos/jacoco/jacoco/issues/331","repository_url":"https://api.github.com/repos/jacoco/jacoco","labels_url":"https://api.github.com/repos/jacoco/jacoco/issues/331/labels{/name}","comments_url":"https://api.github.com/repos/jacoco/jacoco/issues/331/comments","events_url":"https://api.github.com/repos/jacoco/jacoco/issues/331/events","html_url":"https://github.com/jacoco/jacoco/issues/331","id":94072352,"number":331,"title":"java.nio.channels.OverlappingFileLockException for Jacoco offline","user":{"login":"david-wei-wei","id":13216784,"avatar_url":"https://avatars.githubusercontent.com/u/13216784?v=3","gravatar_id":"","url":"https://api.github.com/users/david-wei-wei","html_url":"https://github.com/david-wei-wei","followers_url":"https://api.github.com/users/david-wei-wei/followers","following_url":"https://api.github.com/users/david-wei-wei/following{/other_user}","gists_url":"https://api.github.com/users/david-wei-wei/gists{/gist_id}","starred_url":"https://api.github.com/users/david-wei-wei/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/david-wei-wei/subscriptions","organizations_url":"https://api.github.com/users/david-wei-wei/orgs","repos_url":"https://api.github.com/users/david-wei-wei/repos","events_url":"https://api.github.com/users/david-wei-wei/events{/privacy}","received_events_url":"https://api.github.com/users/david-wei-wei/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/jacoco/jacoco/labels/invalid","name":"invalid","color":"333333"}],"state":"closed","locked":false,"assignee":{"login":"Godin","id":138671,"avatar_url":"https://avatars.githubusercontent.com/u/138671?v=3","gravatar_id":"","url":"https://api.github.com/users/Godin","html_url":"https://github.com/Godin","followers_url":"https://api.github.com/users/Godin/followers","following_url":"https://api.github.com/users/Godin/following{/other_user}","gists_url":"https://api.github.com/users/Godin/gists{/gist_id}","starred_url":"https://api.github.com/users/Godin/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Godin/subscriptions","organizations_url":"https://api.github.com/users/Godin/orgs","repos_url":"https://api.github.com/users/Godin/repos","events_url":"https://api.github.com/users/Godin/events{/privacy}","received_events_url":"https://api.github.com/users/Godin/received_events","type":"User","site_admin":false},"milestone":null,"comments":11,"created_at":"2015-07-09T15:03:00Z","updated_at":"2016-04-14T16:25:25Z","closed_at":"2015-10-02T08:30:53Z","body":"Hi, recently I used Jacoco 0.7.2 to test our AppServer, Encountered such a problem:\r\njava.nio.channels.OverlappingFileLockException \r\nat sun.nio.ch.SharedFileLockTable.checkList(FileLockTable.java:255) \r\nat sun.nio.ch.SharedFileLockTable.add(FileLockTable.java:152) \r\nat sun.nio.ch.FileChannelImpl.lock(FileChannelImpl.java:1030) \r\nat java.nio.channels.FileChannel.lock(FileChannel.java:1053) \r\nat \r\norg.jacoco.agent.rt.internal_e6e56f0.output.FileOutput.openFile(FileOutput.jav \r\na:69) \r\nat \r\norg.jacoco.agent.rt.internal_e6e56f0.output.FileOutput.writeExecutionData(File \r\nOutput.java:53) \r\nat org.jacoco.agent.rt.internal_e6e56f0.Agent.shutdown(Agent.java:137) \r\nat org.jacoco.agent.rt.internal_e6e56f0.Agent$1.run(Agent.java:54) \r\n\r\n In Jacoco Offline, are there different threads to synchronisation/write locking for jacoco.exec in one JVM? In order to avoid concurrent writes from different threads running in parallel in one JVM, I changed some code, it can solve our problem temporarily, as below:\r\n\r\nprivate OutputStream openFile() throws IOException {\r\n  final FileOutputStream file = new FileOutputStream(destFile, append);\r\n  int retries = 5;//retries 5 times\r\n  // Avoid concurrent writes from different agents running in parallel:\r\n  for (int t = 0; t < retries; t++)\r\n  try{\r\n      file.getChannel().lock();\r\n      break;\r\n  }catch(OverlappingFileLockException ofe){\r\n      System.out.println(\"[JACOCO][RT] Got OverlappingFileLockException, re-trying.\");\r\n      try {\r\n                Thread.sleep(1000);\r\n            } catch (InterruptedException e) {\r\n                //ignore\r\n            }\r\n  }\r\n  return file;\r\n }\r\n\r\nPlease help to check the issue."},"comment":{"url":"https://api.github.com/repos/jacoco/jacoco/issues/comments/210034330","html_url":"https://github.com/jacoco/jacoco/issues/331#issuecomment-210034330","issue_url":"https://api.github.com/repos/jacoco/jacoco/issues/331","id":210034330,"user":{"login":"evgen48","id":14019088,"avatar_url":"https://avatars.githubusercontent.com/u/14019088?v=3","gravatar_id":"","url":"https://api.github.com/users/evgen48","html_url":"https://github.com/evgen48","followers_url":"https://api.github.com/users/evgen48/followers","following_url":"https://api.github.com/users/evgen48/following{/other_user}","gists_url":"https://api.github.com/users/evgen48/gists{/gist_id}","starred_url":"https://api.github.com/users/evgen48/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evgen48/subscriptions","organizations_url":"https://api.github.com/users/evgen48/orgs","repos_url":"https://api.github.com/users/evgen48/repos","events_url":"https://api.github.com/users/evgen48/events{/privacy}","received_events_url":"https://api.github.com/users/evgen48/received_events","type":"User","site_admin":false},"created_at":"2016-04-14T16:25:25Z","updated_at":"2016-04-14T16:25:25Z","body":"Hello, I've ram into exact that problem when creating eclipse RCP application, according to jacoco offline instrumentation, jacocoagent.jar should be in class path, since rcp uses own class loaders for different plugins, I had to add jacocoagent.jar both in classpath of junit tests, and in one of RCP module, and got described problem. Agent based instrumentation also not easily possibly for my project, dueto extensive usage of powermock. So I've tried proposed solution with cycle and several attempts to lock file, in my case there were only 1 collision,\r\n`Results :\r\n\r\nTests run: 142, Failures: 0, Errors: 0, Skipped: 10\r\n\r\n[JACOCO][RT] Got OverlappingFileLockException, re-trying.\r\n[INFO] All tests passed!`"}}