Skip to content
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

Cannot build :protobuf_java with Java 9 #4256

Closed
davido opened this issue Jan 31, 2018 · 0 comments
Closed

Cannot build :protobuf_java with Java 9 #4256

davido opened this issue Jan 31, 2018 · 0 comments

Comments

@davido
Copy link
Contributor

davido commented Jan 31, 2018

//CC @cushon @jart

Gerrit Code Review depends on rules_closure, that started to build protobuf_java from source in their build tool chain very recently.

This building of :protobuf_java from source broke Java 9 build support in gerrit ;-(

To reproduce, install the most recent Bazel version: 0.10.rc8, or build Bazel from source, then run in protobuf@HEAD (b718551):

$ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 :protobuf_java
...........
INFO: Analysed target //:protobuf_java (10 packages loaded).
INFO: Found 1 target...
INFO: From Executing genrule @bazel_tools//tools/jdk:gen_platformclasspath [for host]:
Note: external/bazel_tools/tools/jdk/DumpPlatformClassPath.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
ERROR: /home/davido/projects/protobuf/BUILD:604:1: Building libprotobuf_java.jar (78 source files, 1 source jar) failed (Exit 1)
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:44: error: package sun.misc does not exist
  private static final sun.misc.Unsafe UNSAFE = getUnsafe();
                               ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:290: error: package sun.misc does not exist
  private static sun.misc.Unsafe getUnsafe() {
                         ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:427: error: package sun.misc does not exist
    sun.misc.Unsafe unsafe;
            ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:429: error: package sun.misc does not exist
    MemoryAccessor(sun.misc.Unsafe unsafe) {
                           ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:506: error: package sun.misc does not exist
    JvmMemoryAccessor(sun.misc.Unsafe unsafe) {
                              ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:291: error: package sun.misc does not exist
    sun.misc.Unsafe unsafe = null;
            ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:295: error: package sun.misc does not exist
              new PrivilegedExceptionAction<sun.misc.Unsafe>() {
                                                    ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:297: error: package sun.misc does not exist
                public sun.misc.Unsafe run() throws Exception {
                               ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:298: error: package sun.misc does not exist
                  Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
                                ^
java/core/src/main/java/com/google/protobuf/UnsafeUtil.java:298: error: package sun.misc does not exist
                  Class<sun.misc.Unsafe> k = sun.misc.Unsafe.class;
                                                     ^
Target //:protobuf_java failed to build
Use --verbose_failures to see the command lines of failed build steps.
INFO: Elapsed time: 68.809s, Critical Path: 19.64s
davido added a commit to davido/protobuf that referenced this issue Jan 31, 2018
Fixes: protocolbuffers#4256.

Bazel@HEAD supports Java 9.

The current code has one single issue with Java 9 compliance: the usage
of sun.misc package. We add jdk.unsupported module with --add-modules
compiler option for now. Long term, the usage of non public API should
be avoided.

To build with Java 9, build custom bazel version and issue:

  $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \
    --javacopt='--release 9' \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \
   :protobuf_java
lucamilanesio pushed a commit to GerritCodeReview/gerrit that referenced this issue Feb 8, 2018
We need to upgrade rules_closure tools to be able to build with Java 9.
That's because rules_closure depends on dagger 2 and auto-common and
auto-value, that need to be updated to not depend on legacy annotations
(that are not available on Java 9). Moreover, latest rules_closure
switched to building protobuf library from the sources, creating the
next problem: Protobuf doesn't support Java 9 yet. That was fixed only
on master, so that we need to update rules_closure to consume the
protobuf dependency from HEAD.

See these issues for more background: [1],[2],[3],[4].

[1] google/auto#560
[2] bazelbuild/rules_closure#234
[3] google/dagger#880
[4] protocolbuffers/protobuf#4256

Bug: Issue 7958
Change-Id: I56f3b6101e06bd678b4e42d3a9d52157963513aa
zhoutwo pushed a commit to zhoutwo/protobuf that referenced this issue Apr 25, 2020
Fixes: protocolbuffers#4256.

Bazel@HEAD supports Java 9.

The current code has one single issue with Java 9 compliance: the usage
of sun.misc package. We add jdk.unsupported module with --add-modules
compiler option for now. Long term, the usage of non public API should
be avoided.

To build with Java 9, build custom bazel version and issue:

  $ bazel --host_javabase=/usr/lib64/jvm/java-9-openjdk build \
    --javacopt='--release 9' \
    --java_toolchain=@bazel_tools//tools/jdk:toolchain_jdk9 \
   :protobuf_java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants