static int parseMajorJavaVersion(String javaVersion) {
    int version = parseDotted(javaVersion);
    if (version == -1) {
      version = extractBeginningInt(javaVersion);
    }
    if (version == -1) {
      return 6; // Choose minimum supported JDK version as default
    }
    return version;
  }
@Test
  public void testJava9() {
    // Legacy style
    assertThat(JavaVersion.parseMajorJavaVersion("9.0.4")).isEqualTo(9); // Oracle JDK 9
    // Debian as reported in https://github.com/google/gson/issues/1310
    assertThat(JavaVersion.parseMajorJavaVersion("9-Debian")).isEqualTo(9);

    // New style
    assertThat(JavaVersion.parseMajorJavaVersion("9-ea+19")).isEqualTo(9);
    assertThat(JavaVersion.parseMajorJavaVersion("9+100")).isEqualTo(9);
    assertThat(JavaVersion.parseMajorJavaVersion("9.0.1+20")).isEqualTo(9);
    assertThat(JavaVersion.parseMajorJavaVersion("9.1.1+20")).isEqualTo(9);
  }