Skip to content

Troubleshooting: JAVA_HOME is set to an invalid directory

Keegan Witt edited this page Oct 14, 2022 · 9 revisions

Introduction

If you are seeing an error like

ERROR: JAVA_HOME is set to an invalid directory: /opt/java/openjdk
Please set the JAVA_HOME variable in your environment to match the location of your Java installation.

then this article will likely be useful to you.

What happened?

This PR for issue 82 in eclipse-temurin (the base image for these images) changed the default tags from Ubuntu Focal (20.04) to Ubuntu Jammy (22.04). Since at the time, this project was not using tags in the FROM statements that pinned them to Focal, on 22-05-26, this PR then triggered new Gradle images to be published based on Jammy automatically. This is because the build system managed by the Docker Library team automatically rebuilds downstream images so that things like vulnerability patches can be automatically applied.

This means that 7.4.1 and older tags are Ubuntu Focal (20.04) and 7.4.2 and newer tags are Ubuntu Jammy (22.04).

The fact this project did not pin to a specific OS isn't a best practice, but the impact of this wasn't fully appreciated until after the breakage. One of the most significant problems discovered with this upgrade was mentioned in upstream issue 215. @roumigus did some excellent research here, which will be restated and expanded upon here, for posterity.

glibc 2.34 and newer contain this commit, which defaults to using clone3. Ubuntu Jammy ships with 2.35, and thus contains this change in behavior. This meant that newer versions of glibc expected the clone3 system call to be available, which was not in Docker until this change in Docker (fix for 42680). Which is available in Docker versions 20.10.10 and newer.

What fixes have been done to this project?

We now have focal and jammy tags on all applicable image variants. We did not roll back the default tags to Focal. So these are currently Jammy and will always be whatever the latest LTS Ubuntu version that is available from the Eclipse Temurin images going forward. If you want to pin to a specific version of Ubuntu, use one of those new tags.

How can I verify which version of Ubuntu my image is using?

If you have not pulled your image recently, you may still be on a sha that is still using Focal. You can run docker run --rm gradle:[tag-you-are-using] cat /etc/lsb-release to see what version of Ubuntu is on your local image.

What's the fix?

Either

  1. Upgrade your host Docker to 20.10.10 or newer
  2. Switch to a focal image variant.

Potential workaround

Alternatively, if neither of those is an option for some reason, you may be able to invoke Docker with an argument like docker run --security-opt-seccomp=allow_clone3.json. The JSON file should contain the same change as the Docker fix.

{
    "names": [
        "clone3"
    ],
    "action": "SCMP_ACT_ERRNO",
    "errnoRet": 38,
    "excludes": {
        "caps": [
            "CAP_SYS_ADMIN"
        ]
    }
},

See the resources below. This has not been verified.