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

Windows, Java: uncaught exception if JAVA_HOME is undefined [duplicate of #6118] #6475

Closed
laszlocsomor opened this issue Oct 23, 2018 · 2 comments
Labels
area-Windows Windows-specific issues and feature requests team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website untriaged

Comments

@laszlocsomor
Copy link
Contributor

Description of the problem / feature request:

Building a java_binary fails with an uncaught exception when JAVA_HOME is undefined.
Bazel should display an informative error message instead.

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

  1. Build Bazel at 2fda17d

  2. Unset every environment variable except for:

    BAZEL_SH=c:\src\fake-msys\usr\bin\bash.exe
    SystemDrive=C:
    SystemRoot=C:\WINDOWS
    

    The fake MSYS is a C++ binary that prints its arguments then exits with 1.

  3. Create a workspace with just a java_binary rule and a hello world Java file:

    C:\src\tmp>type build
    java_binary(
      name = "hello-java",
      srcs = ["Hello.java"],
      main_class = "Hello",
    )
    
    C:\src\tmp>type hello.java
    public class Hello {
      public static void main(String[] args) {
        System.out.println("hello Java");
      }
    }
    
  4. Try building the target. You'll get an uncaught exception:

    ERROR: C:/users/laszlocsomor/_bazel_laszlocsomor/zovul4l7/external/bazel_tools/tools/jdk/BUILD:197:1: SkylarkAction external/bazel_tools/tools/jdk/platformclasspath.jar failed (Exit 1)
    warning: could not find a JDK 8 bootclasspath in external\local_jdk, falling back to --release
    Exception in thread "main" java.lang.IllegalArgumentException: external\local_jdk
            at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.update(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.file.Locations$SystemModulesLocationHandler.handleOption(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.file.Locations.handleOption(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.file.BaseFileManager$2.handleFileManagerOption(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.main.Option.process(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.main.Option.handleOption(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.file.BaseFileManager.handleOption(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.main.Arguments.doProcessArgs(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.main.Arguments.processArgs(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.main.Arguments.init(Unknown Source)
            at jdk.compiler/com.sun.tools.javac.api.JavacTool.getTask(Unknown Source)
            at DumpPlatformClassPath.dumpJDK9AndNewerBootClassPath(DumpPlatformClassPath.java:141)
            at DumpPlatformClassPath.main(DumpPlatformClassPath.java:76)
    
  5. Finally, set JAVA_HOME to the right value, and try building again. Now it works:

    C:\src\tmp>set JAVA_HOME=c:\Program Files\Java\jdk1.8.0_191
    
    C:\src\tmp>bazel-head.exe build //:hello-java
    ...
    INFO: Build completed successfully, 5 total actions
    

What operating system are you running Bazel on?

Windows Server 2016 (v1607)

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

see above at repro instructions

@laszlocsomor
Copy link
Contributor Author

This is a bad first-time user experience so I'm linking to #5254

@cushon
Copy link
Contributor

cushon commented Oct 23, 2018

This is a duplicate of #6118. That bug discusses a more general fix for recognizing invalid java_runtime configurations, but we could also improve the error handling in DumpPlatformClassPath in the interim.

@aiuto aiuto added area-Windows Windows-specific issues and feature requests untriaged labels Oct 25, 2018
@laszlocsomor laszlocsomor changed the title Windows, Java: uncaught exception if JAVA_HOME is undefined Windows, Java: uncaught exception if JAVA_HOME is undefined [duplicate of #6118] Nov 2, 2018
@philwo philwo added the team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website label Jun 15, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-Windows Windows-specific issues and feature requests team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website untriaged
Projects
None yet
Development

No branches or pull requests

4 participants