-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Overriding javac is broken #11262
Comments
I can reproduce the issue. I say 'the issue' even though it looks more like multiple separate issues. There are three different possible results based on different flag combinations:
1 is not a bug, but simply the combination of a pre-10 compiler (or compiler setting) with code that requires Java 10. I think 2 is a bug in the Java tools, and it seems to be primarily triggered by the custom OpenJDK 11. 3 is clearly an upstream bug, and the use of the custom OpenJDK 11 in combination with pulling in the latest Java tools release seems to avoid hitting it. Unfortunately, that's exactly the combination that runs into issue 2. @cushon, any ideas? |
Thanks @ulfjack. Is there anything else I can supply here? |
That error is happening because the Strict Java Deps implementation depends on a couple of javac bug fixes that are present in the vendored javac, but not in a stock OpenJDK 11 javac. I think JDK-8214026 and JDK-8193277 are sufficient, and those are fixed in JDK 12 and 13 respectively. I tried using JDK 13 with your example and it allows those targets to build: http_archive(
name = "openjdk13_linux_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
sha256 = "3e5dc530c9e9466fc76b860d924876ea93bbdae80a12d47649e11dda3dbd9bac",
strip_prefix = "zulu13.31.11-ca-jdk13.0.3-linux_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu13.31.11-ca-jdk13.0.3-linux_x64.tar.gz",
],
) $ bazel build --host_javabase=@openjdk11_linux_archive//:runtime \
--javabase=@openjdk11_linux_archive//:runtime \
--java_toolchain=//tools/toolchains:jdk11_toolchain \
--host_java_toolchain=//tools/toolchains:jdk11_toolchain \
//java:all
...
JavaBuildTest.java:14: error: [strict] Using type okhttp3.OkHttpClient from an indirect dependency (TOOL_INFO: "~.cache/bazel/_bazel_cushon/29b5745a2b592ce57ecc0334c3961675/execroot/__main__/bazel-out/k8-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/com/squareup/okhttp3/okhttp/3.14.3/okhttp-3.14.3.jar").
OkHttpClient ok = new OkHttpClient.Builder()
^ $ bazel build --host_javabase=@openjdk13_linux_archive//:runtime \
--javabase=@openjdk13_linux_archive//:runtime \
--java_toolchain=//tools/toolchains:jdk11_toolchain \
--host_java_toolchain=//tools/toolchains:jdk11_toolchain \
//java:all
...
INFO: Build completed successfully I hope this is helpful in building an understanding of what's going on, but I'm not sure that using JDK 13 is going to be a practical solution in the short term. It works for those examples, but you'll probably run into other incompatibilities trying to use it for real (e.g. the version of Error Prone that's shipping in Bazel doesn't support JDK 13). |
Great thanks for this. I guess the meta question I’m asking is - what’s the
long term plan here? Is it the separation of the java toolchain into its
own repo, with periodic releases? As I said somewhere else in the issue I
fully understand that this whole thing is intrinsically complicated, both
because toolchains just are, and because bazel is implemented in java; I
also understand that I’m asking a lot from a free and already fantastic
tool. But it would be great to understand how this is likely to work in the
long term, and what the timelines are on reaching that frabjous day.
Thank you
…On Sun, 17 May 2020 at 08:11, Liam Miller-Cushon ***@***.***> wrote:
JavaBuildTest fails to compile with an error involving OkHttpClient,
saying that it comes from an indirect dependency (even though it clearly
comes from a direct dependency)
That error is happening because the Strict Java Deps implementation
depends on a couple of javac bug fixes that are present in the vendored
javac, but not in a stock OpenJDK 11 javac.
I think JDK-8214026 <https://bugs.openjdk.java.net/browse/JDK-8214026>
and JDK-8193277 <https://bugs.openjdk.java.net/browse/JDK-8193277> are
sufficient, and those are fixed in JDK 12 and 13 respectively. I tried
using JDK 13 with your example and it allows those targets to build:
http_archive(
name = "openjdk13_linux_archive",
build_file_content = "java_runtime(name = 'runtime', srcs = glob(['**']), visibility = ['//visibility:public'])",
sha256 = "3e5dc530c9e9466fc76b860d924876ea93bbdae80a12d47649e11dda3dbd9bac",
strip_prefix = "zulu13.31.11-ca-jdk13.0.3-linux_x64",
urls = [
"https://cdn.azul.com/zulu/bin/zulu13.31.11-ca-jdk13.0.3-linux_x64.tar.gz",
],
)
$ bazel build ***@***.***_linux_archive//:runtime \
***@***.***_linux_archive//:runtime \
--java_toolchain=//tools/toolchains:jdk11_toolchain \
--host_java_toolchain=//tools/toolchains:jdk11_toolchain \
//java:all
...
JavaBuildTest.java:14: error: [strict] Using type okhttp3.OkHttpClient from an indirect dependency (TOOL_INFO: "~.cache/bazel/_bazel_cushon/29b5745a2b592ce57ecc0334c3961675/execroot/__main__/bazel-out/k8-fastbuild/bin/external/maven/v1/https/repo1.maven.org/maven2/com/squareup/okhttp3/okhttp/3.14.3/okhttp-3.14.3.jar").
OkHttpClient ok = new OkHttpClient.Builder()
^
$ bazel build ***@***.***_linux_archive//:runtime \
***@***.***_linux_archive//:runtime \
--java_toolchain=//tools/toolchains:jdk11_toolchain \
--host_java_toolchain=//tools/toolchains:jdk11_toolchain \
//java:all
...
INFO: Build completed successfully
I hope this is helpful in building an understanding of what's going on,
but I'm not sure that using JDK 13 is going to be a practical solution in
the short term. It works for those examples, but you'll probably run into
other incompatibilities trying to use it for real (e.g. the version of
Error Prone that's shipping in Bazel doesn't support JDK 13).
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11262 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABN425IQDI22LDYMW5YO44TRR6E37ANCNFSM4MVJIV4A>
.
|
The Java toolchain used in Bazel is a wrapper around the underlying Javac in the JDK. Note that the wrapper already lives in a separate repository with periodic releases (at least, that's the intent), it just uses the Javac in the host JDK. The underlying problem here is that the wrapper uses internal APIs that are not guaranteed to be stable, and so the wrapper has to be updated for every major JDK release. In this specific case, a change in JDK 11 caused the wrapper to misbehave - @cushon fixed that problem in the upstream JDK, but the fix hasn't made it into a minor release of JDK 11 (or maybe it has by now? - I'm not sure how the JDK releases work). It looks like that fix did make it into the Zulu JDK that Bazel is pulling (but that doesn't have the Javac fix? Confusing!). I don't think this is related to Bazel being implemented in Java. One option is to use the vanilla Java builder, which has fewer features, but should be compatible with future JDK releases. I'm not sure if there is any long-term plan to address this inherent discrepancy. I don't suppose we can ask Oracle to maintain Javabuilder for us? |
I see, thanks for the information.
What does the wrapper add to normal javac? Perhaps we could propose API
additions for javac or something?
…On Mon, May 18, 2020 at 9:45 AM Ulf Adams ***@***.***> wrote:
The Java toolchain used in Bazel is a wrapper around the underlying Javac
in the JDK. Note that the wrapper already lives in a separate repository
with periodic releases (at least, that's the intent), it just uses the
Javac in the host JDK. The underlying problem here is that the wrapper uses
internal APIs that are not guaranteed to be stable, and so the wrapper has
to be updated for every major JDK release.
In this specific case, a change in JDK 11 caused the wrapper to misbehave
- @cushon <https://github.com/cushon> fixed that problem in the upstream
JDK, but the fix hasn't made it into a minor release of JDK 11 (or maybe it
has by now? - I'm not sure how the JDK releases work). It looks like that
fix did make it into the Zulu JDK that Bazel is pulling (but that doesn't
have the Javac fix? Confusing!).
I don't think this is related to Bazel being implemented in Java.
One option is to use the vanilla Java builder, which has fewer features,
but should be compatible with future JDK releases.
I'm not sure if there is any long-term plan to address this inherent
discrepancy. I don't suppose we can ask Oracle to maintain Javabuilder for
us?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11262 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABN425MJ4IECHX7MXFCCTYTRSDYRNANCNFSM4MVJIV4A>
.
|
cc @lberki re: long term plans and timelines for
It uses the vendored javac version I mentioned in #11262 (comment), see e.g. 10a4261. The repro is using a stock javac by disabling the configuration that normally causes Bazel to use the vendored JDK: https://github.com/Jonpez2/bazel-custom-java/blob/2808c253508d9420a83cb72ec4ff422d29f69ff9/tools/toolchains/BUILD#L22-L24 |
Thanks @cushon, Error Prone@Head supports JDK 14 now. I uploaded this PR to bump EP release in Bazel (from unknown version 2.3.2-SNAPSHOT) to EP@Head. Based on the above EP upgrade to EP@HEAD with JDK 14 support, I uploaded a PR for Java toolchain 14 support here. I have built and conducted Example project that demonstrates that Java 14 syntax class can be built out of the box is here:
The real world example building with JDK 14 toolchain, Gerrit Code Review built on real CI (with installed vanilla Bazel 3.1.0 only) is here. |
Wow that's great news thank you!
…On Thu, May 28, 2020 at 7:23 AM David Ostrovsky ***@***.***> wrote:
Thanks @cushon <https://github.com/cushon>, Error ***@***.*** supports JDK
14 now.
I uploaded this PR <#11426> to
bump EP release in Bazel (from unknown version 2.3.2-SNAPSHOT) to ***@***.***
I uploaded a PR for toolchain 14 support here
<#11514>.
I have built and conducted java_tools release for JDK 14 toolchain here
<https://github.com/davido/java_tools/releases/tag/v14.0> (currently only
Linux version).
Example project that demonstrates that Java 14 syntax class can be built
out of the box is here <https://github.com/davido/bazel_java_toolchain14>:
$ bazel version
Starting local Bazel server and connecting to it...
Build label: 3.2.0
$ bazel run java
bazel run java:Javac14Example
INFO: Analyzed target //java:Javac14Example (18 packages loaded, 707 targets configured).
INFO: Found 1 target...
INFO: Deleting stale sandbox base /home/davido/.cache/bazel/_bazel_davido/1790aabdce25864b2f68511bd57514be/sandbox
Target //java:Javac14Example up-to-date:
bazel-bin/java/Javac14Example.jar
bazel-bin/java/Javac14Example
INFO: Elapsed time: 9.035s, Critical Path: 0.73s
INFO: 0 processes.
INFO: Build completed successfully, 2 total actions
INFO: Build completed successfully, 2 total actions
0
The real world example building with JDK 14 toolchain, Gerrit Code Review
built on real CI with installed Bazel 3.1.0 only) is here
<https://gerrit-review.googlesource.com/c/gerrit/+/269382>.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11262 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABN425KUTQQV6LPIZYZIWR3RTX7MPANCNFSM4MVJIV4A>
.
|
Now, that Bazel supports Java 14 toolchain with my PR and custom It seems, that Example.java class Example {
public static void main(String[] args) {
java.util.regex.Pattern.compile("(bugs{+#?)(d+)");
}
} Java 8/11 produces different exception on wrong pattern compared to JDK 14/15:
While JDK 14/15 produce
Reproducer in gerrit, with: [1] applied: $ bazel test \
--test_filter=com.google.gerrit.server.project.ProjectConfigTest.readCommentLinkInvalidPattern \
//javatests/com/google/gerrit/server:server_tests
[...]
1) readCommentLinkInvalidPattern(com.google.gerrit.server.project.ProjectConfigTest)
value of:
getValidationErrors().onlyElement()
expected:
…petition near index 4
(bugs{+#?)(d+)
^]
but was:
…petition near index 6
(bugs{+#?)(d+)
^]
at com.google.gerrit.server.project.ProjectConfigTest.readCommentLinkInvalidPattern(ProjectConfigTest.java:573)
FAILURES!!!
Tests run: 1, Failures: 1 //CC @msohn. [1] https://gerrit-review.googlesource.com/c/gerrit/+/269382 |
This seems to have kinda stalled? And I still wonder about the long term
plans for jdk releases, and whether they will always be this painful.
Thank you!
…On Sat, Jun 6, 2020 at 7:38 AM David Ostrovsky ***@***.***> wrote:
Now, that Bazel supports Java 14 toolchain with my PR and custom
java_tools release, it turns out that some tests related to regex
processing for medium size project (Gerrit) are failing: [1].
It seems, that Pattern.compile() behavior has changed between JDK 8/11
and JDK 14/15:
Example.java
class Example {
public static void main(String[] args) {
java.util.regex.Pattern.compile("(bugs{+#?)(d+)");
}
}
Java 8/11 produces different exception on wrong pattern compared to JDK
14/15:
$ java -fullversion
openjdk full version "11.0.7+10-suse-1.1-x8664"
$ java -cp . Example
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 4
(bugs{+#?)(d+)
^
at java.base/java.util.regex.Pattern.error(Pattern.java:2027)
While JDK 14/15 produce
$ java -fullversion
openjdk full version "15-ea+26-1287"
$ java -cp . Example
Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 6
(bugs{+#?)(d+)
^
at java.base/java.util.regex.Pattern.error(Pattern.java:2028)
//CC @msohn <https://github.com/msohn>.
[1] https://gerrit-review.googlesource.com/c/gerrit/+/269382
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#11262 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABN425KD7L6RUOZ3OEODBD3RVHP6VANCNFSM4MVJIV4A>
.
|
@[email protected] <[email protected]> - you got it
through! Thank you so much.
I still have my meta-question about how this will work in the long term.
Who should I ask that of, please? Sorry to be so tediously insistent after
you've done so much.
…On Mon, Jun 22, 2020 at 8:15 AM Jonathan Perry ***@***.***> wrote:
This seems to have kinda stalled? And I still wonder about the long term
plans for jdk releases, and whether they will always be this painful.
Thank you!
On Sat, Jun 6, 2020 at 7:38 AM David Ostrovsky ***@***.***>
wrote:
> Now, that Bazel supports Java 14 toolchain with my PR and custom
> java_tools release, it turns out that some tests related to regex
> processing for medium size project (Gerrit) are failing: [1].
>
> It seems, that Pattern.compile() behavior has changed between JDK 8/11
> and JDK 14/15:
>
> Example.java
>
> class Example {
> public static void main(String[] args) {
> java.util.regex.Pattern.compile("(bugs{+#?)(d+)");
> }
> }
>
> Java 8/11 produces different exception on wrong pattern compared to JDK
> 14/15:
>
> $ java -fullversion
> openjdk full version "11.0.7+10-suse-1.1-x8664"
> $ java -cp . Example
>
> Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 4
> (bugs{+#?)(d+)
> ^
> at java.base/java.util.regex.Pattern.error(Pattern.java:2027)
>
> While JDK 14/15 produce
>
> $ java -fullversion
> openjdk full version "15-ea+26-1287"
>
> $ java -cp . Example
> Exception in thread "main" java.util.regex.PatternSyntaxException: Illegal repetition near index 6
> (bugs{+#?)(d+)
> ^
> at java.base/java.util.regex.Pattern.error(Pattern.java:2028)
>
> //CC @msohn <https://github.com/msohn>.
>
> [1] https://gerrit-review.googlesource.com/c/gerrit/+/269382
>
> —
> You are receiving this because you authored the thread.
> Reply to this email directly, view it on GitHub
> <#11262 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/ABN425KD7L6RUOZ3OEODBD3RVHP6VANCNFSM4MVJIV4A>
> .
>
|
@comius , another use case for your platformization work? |
With Java Platformization work https://docs.google.com/document/d/1MVbBxbKVKRJJY7DnkptHpvz7ROhyAYy4a-TZ-n7Q0r4/edit a lot of issues like this should be resolved. java_tools has been refactored, so that it doesn't include toolchain definitions. It only contains the tools that are needed by the toolchain. This makes it more usable in different Bazel versions, starting after 4.0.0 release. Also a pure Java part and source part of java_tools has been split into a separate repo. Precompiled parts with ijar and singlejar are now really small, and not needed if one has a C compiler. Toolchain definitions are currently part of Bazel, @bazel_tools repository. This should make it way easier to import a new version JDK (e.g 16), because there's no need to fix java_tools. In fact it should be possible to import new JDK by adding couple of rules in the user's repository. In the future when Java rules are rewritten in Starlark, toolchain definitions will be moved into rules_java repository. About javac overrides. Java_toolchain rule has been extended with java_runtime parameter. This way a fixed/pinned JDK is used for compilation. Changing it requires toolchain definition, where I'd say it's user's responsibility to either use vanilla configuration or have a compatible combination of javac and JDK. Or even fix Bazel's javac patches. Additional information is on https://docs.bazel.build/versions/master/bazel-and-java.html |
Description of the problem / feature request:
Attempting to override the javac version to something newer via the advertised mechanisms does not work.
Feature requests: what underlying problem are you trying to solve with this feature?
I am trying to avoid this bug in javac - https://bugs.openjdk.java.net/browse/JDK-8210483
Bugs: what's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.
This repo provides a simple repro of the two different ways we have attempted to solve this, and the problems we ran into with each route. Massive hat tip to https://github.com/AngusDavis, who has been super helpful and wrote the basic repro.
https://github.com/Jonpez2/bazel-custom-java
If you look at the .bazelrc in that repo it has simple instructions on how to repro the problems.
What operating system are you running Bazel on?
uname -a
Linux 4.9.0-12-amd64 #1 SMP Debian 4.9.210-1 (2020-01-20) x86_64 GNU/Linux
What's the output of
bazel info release
?release 3.1.0
What's the output of
git remote get-url origin ; git rev-parse master ; git rev-parse HEAD
?https://github.com/Jonpez2/bazel-custom-java
e0d0b70396c921cdeabf7c54921f347951cbc2bd
e0d0b70396c921cdeabf7c54921f347951cbc2bd
Have you found anything relevant by searching the web?
This google-groups thread summarizes our work so far
https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!topic/bazel-discuss/6wKwd3Xdhk0
The text was updated successfully, but these errors were encountered: