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 5.0rc1 issue with linking Java 17 records with explicit constructors from a different package #14249

Closed
eikemeier opened this issue Nov 9, 2021 · 11 comments
Assignees
Labels
P1 I'll work on this now. (Assignee required) team-Rules-Java Issues for Java rules

Comments

@eikemeier
Copy link

Description of the problem / feature request:

Bazel 5.0rc1 has an issue with linking Java 17 records with explicit constructors from a different package.

Demonstration in eikemeier/bazel_jdk17.

Feature requests: what underlying problem are you trying to solve with this feature?

Compile a Java 17 program with bazel.

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

Check out https://github.com/eikemeier/bazel_jdk17, run bazelisk run //src/main/java/com/example.

What operating system are you running Bazel on?

macOS 10.15

What's the output of bazel info release?

release 5.0.0rc1

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

ssh://git@github.com/eikemeier/bazel_jdk17.git
2c85df80a77291600764d3f193437dec07a41c51
2c85df80a77291600764d3f193437dec07a41c51

Have you found anything relevant by searching the web?

Not really, if you don't count the general Java 17-discussion.

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

See the the README.

@cushon
Copy link
Contributor

cushon commented Nov 9, 2021

ERROR: [...]/bazel_jdk17/src/main/java/com/example/hello/BUILD:3:13: Compiling Java headers src/main/java/com/example/hello/libhello-hjar.jar (1 source file) failed: (Exit 1): java failed: error executing command external/remotejdk17_macos/bin/java [...]

src/main/java/com/example/hello/Hello.java:6: error: unexpected token: {
  public Hello {
               ^
$ cat src/main/java/com/example/hello/Hello.java
package com.example.hello;

import java.util.Objects;

public record Hello(String one) {
  public Hello {
    Objects.requireNonNull(one);
  }
}

@cushon cushon self-assigned this Nov 9, 2021
@eikemeier
Copy link
Author

@cushon: When you move the Hello record in the same package as the Main class the error vanishes. So just the record isn't enough.

@cushon
Copy link
Contributor

cushon commented Nov 9, 2021

That's because header compilation actions only run on Java targets that are dependencies of other targets. The header jar is used as a compile-time optimization when compiling downstream targets, and the action isn't run if record is being built directly.

@eikemeier
Copy link
Author

eikemeier commented Nov 9, 2021

That's because header compilation actions only run on Java targets that are dependencies of other targets. The header jar is used as a compile-time optimization when compiling downstream targets, and the action isn't run if record is being built directly.

Yeah, thanks. So “different package” is probably wrong, it should be “compile unit” or something like that. The same example works in a single package, as long as linking is involved:

https://github.com/eikemeier/bazel_jdk17/tree/single-package

@Wyverald
Copy link
Member

Do we think this is a 5.0 release blocker?

@eikemeier
Copy link
Author

Do we think this is a 5.0 release blocker?

It's a very basic Java 17 program that cannot be compiled. OTOH lots of tools have problems with Java 17, for example Error Prone 2.9.0 (in Bazel 5.0rc1) has issues with records, fixed in 2.10.0:

google/error-prone@47da3af

I don't know what level of Java 17 support is targeted.

copybara-service bot pushed a commit to google/turbine that referenced this issue Nov 10, 2021
@cushon
Copy link
Contributor

cushon commented Nov 10, 2021

I agree this is a very fundamental issue with Java 17 support.

@hvadehra @comius WDYT? I'll have a fix for this ~today, your call whether it makes sense to target 5.0 at this point. (If it doesn't make it into 5.0 it'll still be possible to get the fix by updating the java_tools version, right?)

copybara-service bot pushed a commit to google/turbine that referenced this issue Nov 10, 2021
cushon added a commit to cushon/bazel that referenced this issue Nov 10, 2021
@cushon cushon added team-Rules-Java Issues for Java rules P1 I'll work on this now. (Assignee required) labels Nov 16, 2021
bazel-io pushed a commit that referenced this issue Nov 17, 2021
google/turbine@972d62a

#14249

Partial commit for third_party/*, see #14254.

Signed-off-by: Tony Aiuto <aiuto@google.com>
@cushon
Copy link
Contributor

cushon commented Nov 17, 2021

This is fixed in 268bedd, but will require a java_tools release to be available

@hvadehra
Copy link
Member

I'll try and make a java_tools release today

@cushon cushon added this to the Bazel 5.0 Release Blockers milestone Nov 18, 2021
@hvadehra
Copy link
Member

I'll try and make a java_tools release today

Released and merged in d703b7b

@cushon
Copy link
Contributor

cushon commented Nov 18, 2021

Thanks @hvadehra!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P1 I'll work on this now. (Assignee required) team-Rules-Java Issues for Java rules
Projects
None yet
Development

No branches or pull requests

4 participants