Skip to content

The logic used to find a JDK in various tool operations is unclear and confusing #124252

@andrewkolos

Description

@andrewkolos

Investigation into #122609 revealed that the logic used to to find a java binary for Java-dependent activites was inconsistent across those activities. For more about that logic and how it was inconsistent, see this comment from #122600. While this issue was fixed by making the implementations of Java-finding logic consistent across the tool, this consistency is fragile; because these implementations exist independently of each other. This also isn't the first time this has been noticed (see #9429).

The tool code should be refactored to 1) make JDK-finding logic as explicit as possible1 and 2) make JDK-finding logic as consistent as possible. This should reduce the chance of future confusion and/or introduction of bugs.

Tangentially related: #121501, #106416

Footnotes

  1. For example, gradlew and Android SDK tools (such as avdmanager and sdkmanager) look for Java by first consulting JAVA_HOME on the environment and then java on the path. When invoking those tools, the flutter tool will set JAVA_HOME to the path of the Android Studio-bundled JDK if it exists. This means that the order in which we look for the JDK for these operations is 1) the Android-Studio bundled JDK, 2) JAVA_HOME, and then 3) java on PATH (which java). However, the existence of 2 and 3 is not obvious to those reading only the flutter tool code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P2Important issues not at the top of the work listc: tech-debtTechnical debt, code quality, testing, etc.platform-androidAndroid applications specificallyt: flutter doctorProblem related to the "flutter doctor" tooltoolAffects the "flutter" command-line tool. See also t: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions