{"action":"created","issue":{"url":"https://api.github.com/repos/pantsbuild/pants/issues/3722","repository_url":"https://api.github.com/repos/pantsbuild/pants","labels_url":"https://api.github.com/repos/pantsbuild/pants/issues/3722/labels{/name}","comments_url":"https://api.github.com/repos/pantsbuild/pants/issues/3722/comments","events_url":"https://api.github.com/repos/pantsbuild/pants/issues/3722/events","html_url":"https://github.com/pantsbuild/pants/issues/3722","id":167251858,"number":3722,"title":"We have incorrect assumptions about how zinc finds javac","user":{"login":"benjyw","id":512764,"avatar_url":"https://avatars.githubusercontent.com/u/512764?v=3","gravatar_id":"","url":"https://api.github.com/users/benjyw","html_url":"https://github.com/benjyw","followers_url":"https://api.github.com/users/benjyw/followers","following_url":"https://api.github.com/users/benjyw/following{/other_user}","gists_url":"https://api.github.com/users/benjyw/gists{/gist_id}","starred_url":"https://api.github.com/users/benjyw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjyw/subscriptions","organizations_url":"https://api.github.com/users/benjyw/orgs","repos_url":"https://api.github.com/users/benjyw/repos","events_url":"https://api.github.com/users/benjyw/events{/privacy}","received_events_url":"https://api.github.com/users/benjyw/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/pantsbuild/pants/labels/jvm-compile","name":"jvm-compile","color":"0052cc"}],"state":"open","locked":false,"assignee":{"login":"stuhood","id":46740,"avatar_url":"https://avatars.githubusercontent.com/u/46740?v=3","gravatar_id":"","url":"https://api.github.com/users/stuhood","html_url":"https://github.com/stuhood","followers_url":"https://api.github.com/users/stuhood/followers","following_url":"https://api.github.com/users/stuhood/following{/other_user}","gists_url":"https://api.github.com/users/stuhood/gists{/gist_id}","starred_url":"https://api.github.com/users/stuhood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuhood/subscriptions","organizations_url":"https://api.github.com/users/stuhood/orgs","repos_url":"https://api.github.com/users/stuhood/repos","events_url":"https://api.github.com/users/stuhood/events{/privacy}","received_events_url":"https://api.github.com/users/stuhood/received_events","type":"User","site_admin":false},"assignees":[{"login":"stuhood","id":46740,"avatar_url":"https://avatars.githubusercontent.com/u/46740?v=3","gravatar_id":"","url":"https://api.github.com/users/stuhood","html_url":"https://github.com/stuhood","followers_url":"https://api.github.com/users/stuhood/followers","following_url":"https://api.github.com/users/stuhood/following{/other_user}","gists_url":"https://api.github.com/users/stuhood/gists{/gist_id}","starred_url":"https://api.github.com/users/stuhood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuhood/subscriptions","organizations_url":"https://api.github.com/users/stuhood/orgs","repos_url":"https://api.github.com/users/stuhood/repos","events_url":"https://api.github.com/users/stuhood/events{/privacy}","received_events_url":"https://api.github.com/users/stuhood/received_events","type":"User","site_admin":false},{"login":"benjyw","id":512764,"avatar_url":"https://avatars.githubusercontent.com/u/512764?v=3","gravatar_id":"","url":"https://api.github.com/users/benjyw","html_url":"https://github.com/benjyw","followers_url":"https://api.github.com/users/benjyw/followers","following_url":"https://api.github.com/users/benjyw/following{/other_user}","gists_url":"https://api.github.com/users/benjyw/gists{/gist_id}","starred_url":"https://api.github.com/users/benjyw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benjyw/subscriptions","organizations_url":"https://api.github.com/users/benjyw/orgs","repos_url":"https://api.github.com/users/benjyw/repos","events_url":"https://api.github.com/users/benjyw/events{/privacy}","received_events_url":"https://api.github.com/users/benjyw/received_events","type":"User","site_admin":false}],"milestone":null,"comments":8,"created_at":"2016-07-24T20:15:47Z","updated_at":"2016-07-25T21:32:36Z","closed_at":null,"body":"[Comments](https://github.com/pantsbuild/pants/blob/2914fe05e064359a1381febc974982849937ba20/src/python/pants/backend/jvm/tasks/jvm_compile/zinc/zinc_compile.py#L246) in `zinc_compile.py` imply that Zinc spawns an external javac process if it doesn't find `com.sun.tools.javac.Main` on its classpath. \r\n\r\nBut from browsing the [Zinc source code](https://github.com/pantsbuild/pants/blob/2914fe05e064359a1381febc974982849937ba20/src/scala/org/pantsbuild/zinc/Compiler.scala#L81), this seems inaccurate. In fact, Zinc spawns an external javac only if `-fork-java` or `-java-home` are set, and we set neither of them. So in fact if Zinc cannot find a javac Main class to run in-process, it'll throw a runtime error.\r\n\r\nHowever things are even more complicated than this: Zinc doesn't actually try to classload `com.sun.tools.javac.Main` directly. Instead it delegates to [`javax.tools.ToolProvider.getSystemJavaCompiler`](https://docs.oracle.com/javase/8/docs/api/javax/tools/ToolProvider.html#getSystemJavaCompiler--).\r\n\r\nThat method doesn't seem to care about `com.sun.tools.javac.Main` specifically. Instead it searches for the `com.sun.tools.javac.api.JavacTool` wrapper, and that later gets invoked through the `javax.tools.JavaCompiler` interface it implements.\r\n\r\nSo far, this only means that the comment is inaccurate.  But there's more going on: `getSystemJavaCompiler` searches for that `JavacTool` on the *bootclasspath* only, not the regular classpath.  And if it doesn't find it, it falls back to finding the compiler that comes with the current runtime (if that runtime is a JDK). \r\n\r\nWe put tools.jar on the classpath to make zinc find it there instead of spawning one. But actually zinc will never spawn one, nor will it find it on the classpath. Instead it'll fall through to the one that comes with the JDK we're running Zinc on, which is what we wanted anyway!\r\n\r\nSo we can remove all that tools.jar complexity. Or, if we want to add functionality for using custom java compilers (and that's what I'm trying to do, and what prompted this discovery) then as far as I can tell we need to add it to the bootclasspath, not the regular classpath. \r\n\r\nMy next step will be to try and concoct a test to expose this."},"comment":{"url":"https://api.github.com/repos/pantsbuild/pants/issues/comments/235092259","html_url":"https://github.com/pantsbuild/pants/issues/3722#issuecomment-235092259","issue_url":"https://api.github.com/repos/pantsbuild/pants/issues/3722","id":235092259,"user":{"login":"stuhood","id":46740,"avatar_url":"https://avatars.githubusercontent.com/u/46740?v=3","gravatar_id":"","url":"https://api.github.com/users/stuhood","html_url":"https://github.com/stuhood","followers_url":"https://api.github.com/users/stuhood/followers","following_url":"https://api.github.com/users/stuhood/following{/other_user}","gists_url":"https://api.github.com/users/stuhood/gists{/gist_id}","starred_url":"https://api.github.com/users/stuhood/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/stuhood/subscriptions","organizations_url":"https://api.github.com/users/stuhood/orgs","repos_url":"https://api.github.com/users/stuhood/repos","events_url":"https://api.github.com/users/stuhood/events{/privacy}","received_events_url":"https://api.github.com/users/stuhood/received_events","type":"User","site_admin":false},"created_at":"2016-07-25T21:32:36Z","updated_at":"2016-07-25T21:32:36Z","body":"As mentioned on your rb, we should be able to push-for/participate in upstream zinc changes to unblock this via https://github.com/sbt/zinc/issues/144 , for which we plan to adjust the interaction with `javax.tools.JavaCompiler`."}}
{"actor":{"display_login":"stuhood"}}