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

@bazel_tools//tools/java/runfiles:auto_bazel_repository_processor does not compile with JDK 8 #17458

Closed
nacl opened this issue Feb 9, 2023 · 2 comments
Labels

Comments

@nacl
Copy link

nacl commented Feb 9, 2023

Description of the bug:

Our internal build uses JDK 11 to build code against JDK 8, using the JDK 8 bootclasspath. When upgrading to Bazel 6, the Java runfiles library fails to compile:

external/bazel_tools/tools/java/runfiles/AutoBazelRepositoryProcessor.java:84: error: method iterate in interface Stream<T#2> cannot be applied to given types;
        Stream.iterate(
              ^
  required: T#1,UnaryOperator<T#1>
  found: TypeElement,(element)-[...]ement,Element::g[...]ement
  reason: cannot infer type-variable(s) T#1
    (actual and formal argument lists differ in length)
  where T#1,T#2 are type-variables:
    T#1 extends Object declared in method <T#1>iterate(T#1,UnaryOperator<T#1>)
    T#2 extends Object declared in interface Stream
Target @bazel_tools//tools/java/runfiles:auto_bazel_repository_processor failed to build

This appears to be occurring because the three-argument Stream.iterate method used here:

Stream.iterate(
annotatedClass,
element -> element instanceof TypeElement,
Element::getEnclosingElement)
.map(Element::getSimpleName)
.map(Name::toString)
.collect(toList());

does not exist in JDK 8, there is only a two-argument one. It was added in JDK 9 (JDK 11 docs here.

A simple enough fix would be to replace this Stream call with a for loop, which seems to work for me locally. I can prepare a PR should this be desirable. My understanding is that while Bazel itself needs JDK 11, Bazel should still be able to compile code for JDK 8, including libraries intended to be loaded by end-users like this one.

What's the simplest, easiest way to reproduce this bug? Please provide a minimal example if possible.

Since this only uses the standard library, you can just use javac from JDK 8 without invoking Bazel:

javac tools/java/runfiles/AutoBazelRepositoryProcessor.java

Reproduced using OpenJDK 11 using the OpenJDK 8 bootclasspath, and OpenJDK 8 itself.

Which operating system are you running Bazel on?

Linux (Alma 8 aarch64, CentOS 7 amd64)

What is the output of bazel info release?

6.0.0-vmware

If bazel info release returns development version or (@non-git), tell us how you built Bazel.

No response

What's the output of git remote get-url origin; git rev-parse master; git rev-parse HEAD ?

No response

Have you found anything relevant by searching the web?

#17281 is in the same area, but does not correspond to this precise issue.

Any other information, logs, or outputs that you want to share?

No response

@fmeum
Copy link
Collaborator

fmeum commented Feb 10, 2023

Thanks for the detailed report, I prepared a fix at #17458 that can be cherry-picked into Bazel 6.1.

ShreeM01 added a commit that referenced this issue Feb 16, 2023
The three-argument overload of `Stream#iterate` is only available as of Java 9.

Fixes #17458

Closes #17460.

PiperOrigin-RevId: 509885763
Change-Id: If83d832b3590b8598c0f4163afa3c7054e7c9786

Co-authored-by: Fabian Meumertzheim <fabian@meumertzhe.im>
@pete-gillin-privitar
Copy link

I'm seeing this issue with bazel 6.1.2. (It worked in 5.3.2.) Looking at 420659a, it looks like it made it into various 7.0.0-pre.* builds, but not into any 6.* build. Is it possible to cherry-pick it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants