Skip to content

Commit b0f6d2e

Browse files
cdervclaude
andcommitted
Cache Java version to avoid redundant subprocess call
The check and message functions were both calling getJavaVersion(), spawning the subprocess twice. This created inefficiency and a TOCTOU risk where the Java environment could change between calls. Now check caches the detected version in context.props.javaVersion, and message reads from the cache. The message function is now synchronous since it only reads from context. The InstallPreReq.message type was updated to allow both sync and async functions for flexibility. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 45bfed9 commit b0f6d2e

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

src/tools/impl/verapdf.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,15 @@ const kVersionFileName = "version";
3434
export const verapdfInstallable: InstallableTool = {
3535
name: "VeraPDF",
3636
prereqs: [{
37-
check: async () => {
37+
check: async (context) => {
3838
const javaVersion = await getJavaVersion();
39+
context.props.javaVersion = javaVersion;
3940
return javaVersion !== undefined &&
4041
kSupportedJavaVersions.includes(javaVersion);
4142
},
4243
os: ["darwin", "linux", "windows"],
43-
message: async () => {
44-
const javaVersion = await getJavaVersion();
44+
message: (context) => {
45+
const javaVersion = context.props.javaVersion as number | undefined;
4546
const supportedVersions = kSupportedJavaVersions.join(", ");
4647
if (javaVersion === undefined) {
4748
return `Java is not installed. veraPDF requires Java ${supportedVersions}.`;

src/tools/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ export interface InstallableTool {
3030
export interface InstallPreReq {
3131
check: (context: InstallContext) => Promise<boolean>;
3232
os: string[];
33-
message: string | ((context: InstallContext) => Promise<string>);
33+
message: string | ((context: InstallContext) => string | Promise<string>);
3434
}
3535

3636
// Locally accessible Package information

0 commit comments

Comments
 (0)