From bf12c838ba3f0730c02c0f89b54be42d596538d3 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:39:34 +0000 Subject: [PATCH 1/7] Make the Adoptopenjdk package type look at the Temurin repo first for latest assets --- src/distributions/adopt/installer.ts | 51 +++++++++++++++++++++++++- src/distributions/temurin/installer.ts | 2 +- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index b6393f726..36dde7ab3 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -21,6 +21,7 @@ import { MAX_PAGINATION_PAGES, validatePaginationUrl } from '../../util'; +import {TemurinDistribution, TemurinImplementation} from '../temurin/installer'; export enum AdoptImplementation { Hotspot = 'Hotspot', @@ -30,13 +31,61 @@ export enum AdoptImplementation { export class AdoptDistribution extends JavaBase { constructor( installerOptions: JavaInstallerOptions, - private readonly jvmImpl: AdoptImplementation + private readonly jvmImpl: AdoptImplementation, + private readonly temurinDistribution: TemurinDistribution | null = null ) { super(`Adopt-${jvmImpl}`, installerOptions); + + if (temurinDistribution != null && jvmImpl != AdoptImplementation.Hotspot) { + throw new Error('Only Hotspot JVM is supported by Temurin.'); + } + + // Only use the temurin repo for Hotspot JVMs + if (temurinDistribution == null && jvmImpl == AdoptImplementation.Hotspot) { + this.temurinDistribution = new TemurinDistribution( + installerOptions, + TemurinImplementation.Hotspot + ); + } } protected async findPackageForDownload( version: string + ): Promise { + if (this.jvmImpl == AdoptImplementation.Hotspot) { + core.notice( + "AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration." + ); + } + + if ( + this.jvmImpl == AdoptImplementation.Hotspot && + this.temurinDistribution != null + ) { + try { + const result = await this.temurinDistribution.findPackageForDownload( + version + ); + + if (result != undefined) { + return result; + } + } catch (error) { + if (error.message.includes('Could not find satisfied version')) { + core.notice( + 'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.' + ); + } + } + } + + // failed to find a Temurin version, so fall back to AdoptOpenJDK + return this.findPackageForDownloadOldAdoptOpenJdk(version); + } + + private async findPackageForDownloadOldAdoptOpenJdk( + version: string ): Promise { const availableVersionsRaw = await this.getAvailableVersions(); const availableVersionsWithBinaries = availableVersionsRaw diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index 7e5617cb1..d16d938d6 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -34,7 +34,7 @@ export class TemurinDistribution extends JavaBase { super(`Temurin-${jvmImpl}`, installerOptions); } - protected async findPackageForDownload( + public async findPackageForDownload( version: string ): Promise { const availableVersionsRaw = await this.getAvailableVersions(); From 7d2d456be4e871e533d34da00a8eb3a03cce5056 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:49:40 +0000 Subject: [PATCH 2/7] Address Copilot code review comments - Use strict equality (===, !==) instead of loose equality (==, !=) for all comparisons - Properly handle caught errors with instanceof type narrowing before accessing properties - Only fall back to legacy AdoptOpenJDK for specific version-not-found errors - Rethrow unexpected errors to avoid masking real issues (network failures, rate limits, etc.) - Fix error message check to match actual error text ('No matching version found') - Remove unnecessary undefined check since method return type is never undefined - Add @internal JSDoc annotation to TemurinDistribution.findPackageForDownload() - Update tests to properly mock Temurin lookup failures for fallback behavior testing - Rebuild dist files --- .../distributors/adopt-installer.test.ts | 16 +++++++ dist/setup/index.js | 44 ++++++++++++++++++- src/distributions/adopt/installer.ts | 36 +++++++++------ src/distributions/temurin/installer.ts | 3 ++ 4 files changed, 85 insertions(+), 14 deletions(-) diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 55649255b..9accc2663 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -278,6 +278,10 @@ describe('findPackageForDownload', () => { }, AdoptImplementation.Hotspot ); + // Mock Temurin to fail so fallback to AdoptOpenJDK is tested + distribution['temurinDistribution']!['findPackageForDownload'] = async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; const resolvedVersion = await distribution['findPackageForDownload'](input); expect(resolvedVersion.version).toBe(expected); @@ -293,6 +297,10 @@ describe('findPackageForDownload', () => { }, AdoptImplementation.Hotspot ); + // Mock Temurin to fail so fallback to AdoptOpenJDK is tested + distribution['temurinDistribution']!['findPackageForDownload'] = async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; await expect( distribution['findPackageForDownload']('9.0.8') @@ -309,6 +317,10 @@ describe('findPackageForDownload', () => { }, AdoptImplementation.Hotspot ); + // Mock Temurin to fail so fallback to AdoptOpenJDK is tested + distribution['temurinDistribution']!['findPackageForDownload'] = async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow( /No matching version found for SemVer */ @@ -325,6 +337,10 @@ describe('findPackageForDownload', () => { }, AdoptImplementation.Hotspot ); + // Mock Temurin to fail so fallback to AdoptOpenJDK is tested + distribution['temurinDistribution']!['findPackageForDownload'] = async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => []; await expect(distribution['findPackageForDownload']('11')).rejects.toThrow( /No matching version found for SemVer */ diff --git a/dist/setup/index.js b/dist/setup/index.js index 16fca2a58..0d4176d24 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77815,17 +77815,56 @@ const path_1 = __importDefault(__nccwpck_require__(71017)); const semver_1 = __importDefault(__nccwpck_require__(11383)); const base_installer_1 = __nccwpck_require__(59741); const util_1 = __nccwpck_require__(92629); +const installer_1 = __nccwpck_require__(18579); var AdoptImplementation; (function (AdoptImplementation) { AdoptImplementation["Hotspot"] = "Hotspot"; AdoptImplementation["OpenJ9"] = "OpenJ9"; })(AdoptImplementation || (exports.AdoptImplementation = AdoptImplementation = {})); class AdoptDistribution extends base_installer_1.JavaBase { - constructor(installerOptions, jvmImpl) { + constructor(installerOptions, jvmImpl, temurinDistribution = null) { super(`Adopt-${jvmImpl}`, installerOptions); this.jvmImpl = jvmImpl; + this.temurinDistribution = temurinDistribution; + if (temurinDistribution !== null && + jvmImpl !== AdoptImplementation.Hotspot) { + throw new Error('Only Hotspot JVM is supported by Temurin.'); + } + // Only use the temurin repo for Hotspot JVMs + if (temurinDistribution === null && + jvmImpl === AdoptImplementation.Hotspot) { + this.temurinDistribution = new installer_1.TemurinDistribution(installerOptions, installer_1.TemurinImplementation.Hotspot); + } } findPackageForDownload(version) { + return __awaiter(this, void 0, void 0, function* () { + if (this.jvmImpl === AdoptImplementation.Hotspot) { + core.notice("AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration."); + } + if (this.jvmImpl === AdoptImplementation.Hotspot && + this.temurinDistribution !== null) { + try { + return yield this.temurinDistribution.findPackageForDownload(version); + } + catch (error) { + // Only fall back to legacy AdoptOpenJDK for version-not-found errors + if (error instanceof Error && + error.message.includes('No matching version found')) { + core.notice('The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'); + } + else { + // Rethrow unexpected errors to avoid masking real issues + core.debug(`Unexpected error from Temurin lookup: ${error instanceof Error ? error.message : String(error)}`); + throw error; + } + } + } + // failed to find a Temurin version, so fall back to AdoptOpenJDK + return this.findPackageForDownloadOldAdoptOpenJdk(version); + }); + } + findPackageForDownloadOldAdoptOpenJdk(version) { return __awaiter(this, void 0, void 0, function* () { const availableVersionsRaw = yield this.getAvailableVersions(); const availableVersionsWithBinaries = availableVersionsRaw @@ -80195,6 +80234,9 @@ class TemurinDistribution extends base_installer_1.JavaBase { super(`Temurin-${jvmImpl}`, installerOptions); this.jvmImpl = jvmImpl; } + /** + * @internal For cross-distribution reuse only. Not intended as a public API. + */ findPackageForDownload(version) { return __awaiter(this, void 0, void 0, function* () { const availableVersionsRaw = yield this.getAvailableVersions(); diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 36dde7ab3..a8c6f57b8 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -36,12 +36,18 @@ export class AdoptDistribution extends JavaBase { ) { super(`Adopt-${jvmImpl}`, installerOptions); - if (temurinDistribution != null && jvmImpl != AdoptImplementation.Hotspot) { + if ( + temurinDistribution !== null && + jvmImpl !== AdoptImplementation.Hotspot + ) { throw new Error('Only Hotspot JVM is supported by Temurin.'); } // Only use the temurin repo for Hotspot JVMs - if (temurinDistribution == null && jvmImpl == AdoptImplementation.Hotspot) { + if ( + temurinDistribution === null && + jvmImpl === AdoptImplementation.Hotspot + ) { this.temurinDistribution = new TemurinDistribution( installerOptions, TemurinImplementation.Hotspot @@ -52,30 +58,34 @@ export class AdoptDistribution extends JavaBase { protected async findPackageForDownload( version: string ): Promise { - if (this.jvmImpl == AdoptImplementation.Hotspot) { + if (this.jvmImpl === AdoptImplementation.Hotspot) { core.notice( "AdoptOpenJDK has moved to Eclipse Temurin https://github.com/actions/setup-java#supported-distributions please consider changing to the 'temurin' distribution type in your setup-java configuration." ); } if ( - this.jvmImpl == AdoptImplementation.Hotspot && - this.temurinDistribution != null + this.jvmImpl === AdoptImplementation.Hotspot && + this.temurinDistribution !== null ) { try { - const result = await this.temurinDistribution.findPackageForDownload( - version - ); - - if (result != undefined) { - return result; - } + return await this.temurinDistribution.findPackageForDownload(version); } catch (error) { - if (error.message.includes('Could not find satisfied version')) { + // Only fall back to legacy AdoptOpenJDK for version-not-found errors + if ( + error instanceof Error && + error.message.includes('No matching version found') + ) { core.notice( 'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.' ); + } else { + // Rethrow unexpected errors to avoid masking real issues + core.debug( + `Unexpected error from Temurin lookup: ${error instanceof Error ? error.message : String(error)}` + ); + throw error; } } } diff --git a/src/distributions/temurin/installer.ts b/src/distributions/temurin/installer.ts index d16d938d6..109c2d413 100644 --- a/src/distributions/temurin/installer.ts +++ b/src/distributions/temurin/installer.ts @@ -34,6 +34,9 @@ export class TemurinDistribution extends JavaBase { super(`Temurin-${jvmImpl}`, installerOptions); } + /** + * @internal For cross-distribution reuse only. Not intended as a public API. + */ public async findPackageForDownload( version: string ): Promise { From 5d3f13625c438f813a5a917213f7b1ea762a6786 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:53:18 +0000 Subject: [PATCH 3/7] Always fall back to legacy AdoptOpenJDK but log all Temurin failures - Change error handling to gracefully fall back for all errors, not just version-not-found - Log version-not-found errors as notices with migration guidance - Log other Temurin failures as debug messages for troubleshooting - Improves resilience: users always get a result even if Temurin API has issues - Maintains visibility: failures are still logged for debugging --- dist/setup/index.js | 11 +++++------ src/distributions/adopt/installer.ts | 13 +++++-------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 0d4176d24..18c4633ed 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77847,16 +77847,15 @@ class AdoptDistribution extends base_installer_1.JavaBase { return yield this.temurinDistribution.findPackageForDownload(version); } catch (error) { - // Only fall back to legacy AdoptOpenJDK for version-not-found errors - if (error instanceof Error && - error.message.includes('No matching version found')) { + // Log the failure but always fall back to legacy AdoptOpenJDK for resilience + const errorMessage = error instanceof Error ? error.message : String(error); + if (errorMessage.includes('No matching version found')) { core.notice('The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'); } else { - // Rethrow unexpected errors to avoid masking real issues - core.debug(`Unexpected error from Temurin lookup: ${error instanceof Error ? error.message : String(error)}`); - throw error; + // Log other errors for debugging but gracefully fall back + core.debug(`Temurin lookup failed: ${errorMessage}. Falling back to AdoptOpenJDK API.`); } } } diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index a8c6f57b8..edfc0f3b8 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -71,21 +71,18 @@ export class AdoptDistribution extends JavaBase { try { return await this.temurinDistribution.findPackageForDownload(version); } catch (error) { - // Only fall back to legacy AdoptOpenJDK for version-not-found errors - if ( - error instanceof Error && - error.message.includes('No matching version found') - ) { + // Log the failure but always fall back to legacy AdoptOpenJDK for resilience + const errorMessage = error instanceof Error ? error.message : String(error); + if (errorMessage.includes('No matching version found')) { core.notice( 'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.' ); } else { - // Rethrow unexpected errors to avoid masking real issues + // Log other errors for debugging but gracefully fall back core.debug( - `Unexpected error from Temurin lookup: ${error instanceof Error ? error.message : String(error)}` + `Temurin lookup failed: ${errorMessage}. Falling back to AdoptOpenJDK API.` ); - throw error; } } } From d8f95befc80800afe43dbc5d99a33e0c82369a6f Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 11:55:12 +0000 Subject: [PATCH 4/7] Fixes from review --- package-lock.json | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/package-lock.json b/package-lock.json index b910a8f01..208a2e9e2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6470,21 +6470,6 @@ "node": ">=16.0.0" } }, - "node_modules/xml-naming": { - "version": "0.1.0", - "resolved": "https://registry.npmjs.org/xml-naming/-/xml-naming-0.1.0.tgz", - "integrity": "sha512-k8KO9hrMyNk6tUWqUfkTEZbezRRpONVOzUTnc97VnCvyj6Tf9lyUR9EDAIeiVLv56jsMcoXEwjW8Kv5yPY52lw==", - "funding": [ - { - "type": "github", - "url": "https://github.com/sponsors/NaturalIntelligence" - } - ], - "license": "MIT", - "engines": { - "node": ">=16.0.0" - } - }, "node_modules/xmlbuilder2": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/xmlbuilder2/-/xmlbuilder2-4.0.3.tgz", From b8110ecdf3a020ea6e0440579d7a04d1c5df18a1 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:07:36 +0000 Subject: [PATCH 5/7] Fixes from review --- dist/setup/index.js | 9 ++++----- src/distributions/adopt/installer.ts | 21 +++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 18c4633ed..1ec389929 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77825,16 +77825,15 @@ class AdoptDistribution extends base_installer_1.JavaBase { constructor(installerOptions, jvmImpl, temurinDistribution = null) { super(`Adopt-${jvmImpl}`, installerOptions); this.jvmImpl = jvmImpl; - this.temurinDistribution = temurinDistribution; if (temurinDistribution !== null && jvmImpl !== AdoptImplementation.Hotspot) { throw new Error('Only Hotspot JVM is supported by Temurin.'); } // Only use the temurin repo for Hotspot JVMs - if (temurinDistribution === null && - jvmImpl === AdoptImplementation.Hotspot) { - this.temurinDistribution = new installer_1.TemurinDistribution(installerOptions, installer_1.TemurinImplementation.Hotspot); - } + this.temurinDistribution = + temurinDistribution !== null && temurinDistribution !== void 0 ? temurinDistribution : (jvmImpl === AdoptImplementation.Hotspot + ? new installer_1.TemurinDistribution(installerOptions, installer_1.TemurinImplementation.Hotspot) + : null); } findPackageForDownload(version) { return __awaiter(this, void 0, void 0, function* () { diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index edfc0f3b8..00a1a6b38 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -29,10 +29,12 @@ export enum AdoptImplementation { } export class AdoptDistribution extends JavaBase { + private readonly temurinDistribution: TemurinDistribution | null; + constructor( installerOptions: JavaInstallerOptions, private readonly jvmImpl: AdoptImplementation, - private readonly temurinDistribution: TemurinDistribution | null = null + temurinDistribution: TemurinDistribution | null = null ) { super(`Adopt-${jvmImpl}`, installerOptions); @@ -44,15 +46,14 @@ export class AdoptDistribution extends JavaBase { } // Only use the temurin repo for Hotspot JVMs - if ( - temurinDistribution === null && - jvmImpl === AdoptImplementation.Hotspot - ) { - this.temurinDistribution = new TemurinDistribution( - installerOptions, - TemurinImplementation.Hotspot - ); - } + this.temurinDistribution = + temurinDistribution ?? + (jvmImpl === AdoptImplementation.Hotspot + ? new TemurinDistribution( + installerOptions, + TemurinImplementation.Hotspot + ) + : null); } protected async findPackageForDownload( From 4826c07bc151bffdae770986d54dee7dfd5dadc0 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:13:25 +0000 Subject: [PATCH 6/7] Fixes from review --- .../distributors/adopt-installer.test.ts | 61 +++++++++++++++---- dist/setup/index.js | 7 ++- src/distributions/adopt/installer.ts | 5 +- src/distributions/base-installer.ts | 4 +- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/__tests__/distributors/adopt-installer.test.ts b/__tests__/distributors/adopt-installer.test.ts index 9accc2663..05be8d53c 100644 --- a/__tests__/distributors/adopt-installer.test.ts +++ b/__tests__/distributors/adopt-installer.test.ts @@ -4,6 +4,7 @@ import { AdoptDistribution, AdoptImplementation } from '../../src/distributions/adopt/installer'; +import {TemurinDistribution} from '../../src/distributions/temurin/installer'; import {JavaInstallerOptions} from '../../src/distributions/base-models'; import os from 'os'; @@ -256,6 +257,38 @@ describe('getAvailableVersions', () => { }); describe('findPackageForDownload', () => { + it('returns Temurin result and does not query Adopt API when Temurin succeeds', async () => { + const temurinRelease = { + version: '11.0.31+11', + url: 'https://example.test/temurin-11.tar.gz' + }; + const temurinFindPackageForDownload = jest + .fn() + .mockResolvedValue(temurinRelease); + const temurinDistribution = { + findPackageForDownload: temurinFindPackageForDownload + } as unknown as TemurinDistribution; + + const distribution = new AdoptDistribution( + { + version: '11', + architecture: 'x64', + packageType: 'jdk', + checkLatest: false + }, + AdoptImplementation.Hotspot, + temurinDistribution + ); + const adoptLookupSpy = jest.fn(); + distribution['getAvailableVersions'] = adoptLookupSpy; + + const resolvedVersion = await distribution['findPackageForDownload']('11'); + + expect(resolvedVersion).toEqual(temurinRelease); + expect(temurinFindPackageForDownload).toHaveBeenCalledWith('11'); + expect(adoptLookupSpy).not.toHaveBeenCalled(); + }); + it.each([ ['9', '9.0.7+10'], ['15', '15.0.2+7'], @@ -279,9 +312,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; const resolvedVersion = await distribution['findPackageForDownload'](input); expect(resolvedVersion.version).toBe(expected); @@ -298,9 +332,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; await expect( distribution['findPackageForDownload']('9.0.8') @@ -318,9 +353,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => manifestData as any; await expect(distribution['findPackageForDownload']('7.x')).rejects.toThrow( /No matching version found for SemVer */ @@ -338,9 +374,10 @@ describe('findPackageForDownload', () => { AdoptImplementation.Hotspot ); // Mock Temurin to fail so fallback to AdoptOpenJDK is tested - distribution['temurinDistribution']!['findPackageForDownload'] = async () => { - throw new Error('No matching version found for SemVer'); - }; + distribution['temurinDistribution']!['findPackageForDownload'] = + async () => { + throw new Error('No matching version found for SemVer'); + }; distribution['getAvailableVersions'] = async () => []; await expect(distribution['findPackageForDownload']('11')).rejects.toThrow( /No matching version found for SemVer */ diff --git a/dist/setup/index.js b/dist/setup/index.js index 1ec389929..2273faf27 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77848,7 +77848,8 @@ class AdoptDistribution extends base_installer_1.JavaBase { catch (error) { // Log the failure but always fall back to legacy AdoptOpenJDK for resilience const errorMessage = error instanceof Error ? error.message : String(error); - if (errorMessage.includes('No matching version found')) { + if (error instanceof Error && + error.name === 'VersionNotFoundError') { core.notice('The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'); } @@ -78260,7 +78261,9 @@ class JavaBase { parts.push(`(showing first ${maxVersionsToShow} of ${availableVersions.length} versions, enable debug mode to see all)`); } } - return new Error(parts.join('\n')); + const error = new Error(parts.join('\n')); + error.name = 'VersionNotFoundError'; + return error; } setJavaDefault(version, toolPath) { const majorVersion = version.split('.')[0]; diff --git a/src/distributions/adopt/installer.ts b/src/distributions/adopt/installer.ts index 00a1a6b38..78798bfc1 100644 --- a/src/distributions/adopt/installer.ts +++ b/src/distributions/adopt/installer.ts @@ -73,8 +73,9 @@ export class AdoptDistribution extends JavaBase { return await this.temurinDistribution.findPackageForDownload(version); } catch (error) { // Log the failure but always fall back to legacy AdoptOpenJDK for resilience - const errorMessage = error instanceof Error ? error.message : String(error); - if (errorMessage.includes('No matching version found')) { + const errorMessage = + error instanceof Error ? error.message : String(error); + if (error instanceof Error && error.name === 'VersionNotFoundError') { core.notice( 'The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.' diff --git a/src/distributions/base-installer.ts b/src/distributions/base-installer.ts index 10e37d996..5d9f3c82a 100644 --- a/src/distributions/base-installer.ts +++ b/src/distributions/base-installer.ts @@ -292,7 +292,9 @@ export abstract class JavaBase { } } - return new Error(parts.join('\n')); + const error = new Error(parts.join('\n')); + error.name = 'VersionNotFoundError'; + return error; } protected setJavaDefault(version: string, toolPath: string) { From 041d924d8bf6ffc8c2ff8adb8d2c3029818a4340 Mon Sep 17 00:00:00 2001 From: John <1615532+johnoliver@users.noreply.github.com> Date: Fri, 12 Jun 2026 12:28:17 +0000 Subject: [PATCH 7/7] Regenerate dist --- dist/setup/index.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dist/setup/index.js b/dist/setup/index.js index 2273faf27..a2efc14ae 100644 --- a/dist/setup/index.js +++ b/dist/setup/index.js @@ -77848,8 +77848,7 @@ class AdoptDistribution extends base_installer_1.JavaBase { catch (error) { // Log the failure but always fall back to legacy AdoptOpenJDK for resilience const errorMessage = error instanceof Error ? error.message : String(error); - if (error instanceof Error && - error.name === 'VersionNotFoundError') { + if (error instanceof Error && error.name === 'VersionNotFoundError') { core.notice('The JVM you are looking for could not be found in the Temurin repository, this likely indicates ' + 'that you are using an out of date version of Java, consider updating and moving to using the Temurin distribution type in setup-java.'); }