Skip to content

Commit

Permalink
@W17370746@ Java Version identification bug fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
jfeingold35 committed Dec 5, 2024
1 parent d4d9840 commit 335641e
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/lib/JreSetupManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ class JreSetupManager extends AsyncCreatable {
}

private async verifyJavaVersion(javaHome: string): Promise<void> {
const versionCommandOut = await this.fetchJavaVersion(javaHome);
let versionCommandOut: string;
try {
versionCommandOut = await this.fetchJavaVersion(javaHome);
} catch (e) {
const msg: string = e instanceof Error ? e.message : e as string;
throw new SfError(msg, 'CouldNotFindJavaVersion');
}

// We are using "java -version" below which has output that typically looks like:
// * (from MacOS): "openjdk version "11.0.6" 2020-01-14 LTS\nOpenJDK Runtime Environment Zulu11.37+17-CA (build 11.0.6+10-LTS)\nOpenJDK 64-Bit Server VM Zulu11.37+17-CA (build 11.0.6+10-LTS, mixed mode)\n"
Expand Down
24 changes: 24 additions & 0 deletions test/lib/JreSetupManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,30 @@ describe('JreSetupManager #verifyJreSetup', () => {
statStub.restore();
});

it('should fail when valid path is found, but Java version cannot be returned', async () => {
// More stubbing
Sinon.stub(Config.prototype, 'getJavaHome').returns(javaHomeValidPath);
// FileHandler claims the path is valid.
Sinon.stub(FileHandler.prototype, 'stats').resolves();
// Error indicates that version could not be retrieved.
Sinon.stub(childProcess, 'execFile').yields(error, emptyStdout, 'irrelevant');

// Execute and verify
let threw = false;
let name: string = '';
let message: string = '';
try {
await verifyJreSetup();
} catch (err) {
threw = true;
name = err.name;
message = err instanceof Error ? err.message : err as string;
}
expect(threw).equals(true);
expect(message).contains('Could not fetch Java version from path');
expect(name).equals('CouldNotFindJavaVersion');
});

it('should fail when valid path is found, but Java version is not acceptable', async () => {
// More stubbing
const configGetJavaHomeStub = Sinon.stub(Config.prototype, 'getJavaHome').returns(javaHomeValidPath);
Expand Down

0 comments on commit 335641e

Please sign in to comment.