Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/configurationProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import * as anchor from "./anchor";
import { buildWorkspace } from "./build";
import * as commands from "./commands";
import * as lsPlugin from "./languageServerPlugin";
import { detectLaunchCommandStyle, validateRuntime } from "./launchCommand";
import { addMoreHelpfulVMArgs, detectLaunchCommandStyle, validateRuntime } from "./launchCommand";
import { logger, Type } from "./logger";
import { resolveProcessId } from "./processPicker";
import * as utility from "./utility";
Expand Down Expand Up @@ -222,6 +222,9 @@ export class JavaDebugConfigurationProvider implements vscode.DebugConfiguration
validateRuntime(config);
}

// Add more helpful vmArgs.
await addMoreHelpfulVMArgs(config);

if (!config.shortenCommandLine || config.shortenCommandLine === "auto") {
config.shortenCommandLine = await detectLaunchCommandStyle(config);
}
Expand Down
19 changes: 19 additions & 0 deletions src/launchCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ enum shortenApproach {
argfile = "argfile",
}

const HELPFUL_NPE_VMARGS = "-XX:+ShowCodeDetailsInExceptionMessages";

export async function detectLaunchCommandStyle(config: vscode.DebugConfiguration): Promise<shortenApproach> {
const javaExec: string = config.javaExec || path.join(await getJavaHome(), "bin", "java");
const javaVersion = await checkJavaVersion(javaExec);
Expand All @@ -40,6 +42,23 @@ export async function validateRuntime(config: vscode.DebugConfiguration) {
}
}

export async function addMoreHelpfulVMArgs(config: vscode.DebugConfiguration) {
try {
const javaExec = config.javaExec || path.join(await getJavaHome(), "bin", "java");
const version = await checkJavaVersion(javaExec);
if (version >= 14) {
// JEP-358: https://openjdk.java.net/jeps/358
if (config.vmArgs && config.vmArgs.indexOf(HELPFUL_NPE_VMARGS) >= 0) {
return;
}

config.vmArgs = (config.vmArgs || "") + " " + HELPFUL_NPE_VMARGS;
}
} catch (error) {
// do nothing.
}
}

function checkJavaVersion(javaExec: string): Promise<number> {
return new Promise((resolve, reject) => {
cp.execFile(javaExec, ["-version"], {}, (error, stdout, stderr) => {
Expand Down