{"record":{"id":"67e2fcf3a673b396","repo":"java-native-access/jna","slug":"bad-volume-guid-path-format","errorCode":null,"errorMessage":"Bad volume GUID path format: ","messagePattern":"Bad volume GUID path format: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"warning","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java","lineNumber":906,"sourceCode":"\n    /**\n     * Parses and returns the pure GUID value of a volume name obtained\n     * from {@link Kernel32#FindFirstVolume(char[], int)} or\n     * {@link Kernel32#FindNextVolume} calls\n     *\n     * @param volumeGUIDPath\n     *              The volume GUID path as returned by one of the above mentioned calls\n     * @return The pure GUID value after stripping the &quot;\\\\?\\&quot; prefix and\n     * removing the trailing backslash.\n     * @throws IllegalArgumentException if bad format encountered\n     * @see <A HREF=\"https://msdn.microsoft.com/en-us/library/windows/desktop/aa365248(v=vs.85).aspx\">Naming a Volume</A>\n     */\n    public static final String extractVolumeGUID(String volumeGUIDPath) {\n        if ((volumeGUIDPath == null)\n            || (volumeGUIDPath.length() <= (VOLUME_GUID_PATH_PREFIX.length() + VOLUME_GUID_PATH_SUFFIX.length()))\n            || (!volumeGUIDPath.startsWith(VOLUME_GUID_PATH_PREFIX))\n            || (!volumeGUIDPath.endsWith(VOLUME_GUID_PATH_SUFFIX))) {\n            throw new IllegalArgumentException(\"Bad volume GUID path format: \" + volumeGUIDPath);\n        }\n\n        return volumeGUIDPath.substring(VOLUME_GUID_PATH_PREFIX.length(), volumeGUIDPath.length() - VOLUME_GUID_PATH_SUFFIX.length());\n    }\n\n    /**\n     * This function retrieves the full path of the executable file of a given process identifier.\n     *\n     * @param pid\n     *          Identifier for the running process\n     * @param dwFlags\n     *          0 - The name should use the Win32 path format.\n     *          1(WinNT.PROCESS_NAME_NATIVE) - The name should use the native system path format.\n     *\n     * @return the full path of the process's executable file of null if failed. To get extended error information,\n     *         call GetLastError.\n     */\n    public static final String QueryFullProcessImageName(int pid, int dwFlags) {","sourceCodeStart":888,"sourceCodeEnd":924,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Kernel32Util.java#L888-L924","documentation":"extractVolumeGUID extracts the bare GUID from a volume path like \\\\?\\Volume{GUID}\\ by stripping the known prefix and suffix. It throws IllegalArgumentException when the input is null, too short, or does not start with \\\\?\\Volume{ and end with }\\. This is a pure client-side format validation — no native call is involved, so GetLastError is irrelevant here.","triggerScenarios":"Calling Kernel32Util.extractVolumeGUID with null, an empty string, a bare GUID without the \\\\?\\Volume{...}\\ wrapper, a path missing the trailing backslash, or a drive letter like \"C:\\\".","commonSituations":"Passing the output of GetVolumeNameForVolumeMountPoint that was concatenated or trimmed incorrectly; stripping the backslash with a manual substring; passing the extracted GUID back in instead of the full path; hardcoding a GUID string and mistyping braces.","solutions":["Pass the full volume path exactly as returned by FindFirstVolume/GetVolumeNameForVolumeMountPoint, including trailing backslash.","Validate the format with a regex ^\\\\\\\\\\?\\\\Volume\\{[0-9a-fA-F-]+\\}\\\\$ before calling.","If you only have a bare GUID, rebuild the path: \"\\\\\\\\?\\\\Volume{\" + guid + \"}\\\\\".","Catch IllegalArgumentException at call boundaries accepting user/registry-supplied strings."],"exampleFix":"// before\nString guid = Kernel32Util.extractVolumeGUID(\"{abcd1234}\"); // throws\n\n// after\nString path = \"{abcd1234}\".matches(\"^\\\\\\\\\\\\?\\\\\\\\Volume\\\\{.+\\\\}\\\\\\\\$\")\n    ? \"{abcd1234}\"\n    : \"\\\\\\\\?\\\\Volume{\" + \"{abcd1234}\" + \"}\\\\\";\nString guid = Kernel32Util.extractVolumeGUID(path);","handlingStrategy":"validation","validationCode":"static final Pattern VOLUME_GUID = Pattern.compile(\"^\\\\\\\\\\\\?\\\\\\\\Volume\\\\{([0-9a-fA-F\\\\-]+)\\\\}\\\\\\\\$\");\nMatcher m = VOLUME_GUID.matcher(volumeGUIDPath);\nif (!m.matches()) throw new IllegalArgumentException(volumeGUIDPath);\nString guid = m.group(1); // same result as extractVolumeGUID, validated first","typeGuard":"static boolean isWellFormedVolumeGuidPath(String s) {\n    return s != null && s.matches(\"^\\\\\\\\\\\\?\\\\\\\\Volume\\\\{[0-9a-fA-F\\\\-]+\\\\}\\\\\\\\$\");\n}","tryCatchPattern":"try {\n    guid = Kernel32Util.extractVolumeGUID(path);\n} catch (IllegalArgumentException e) {\n    LOG.warn(\"Malformed volume path: \" + path);\n    guid = null;\n}","preventionTips":["Keep the trailing backslash — it is part of the required format.","Only feed paths straight from FindFirstVolume/GetVolumeNameForVolumeMountPoint into the extractor.","Do not pass an already-extracted GUID back into the extractor.","Use a regex pre-check when input comes from users or the registry."],"tags":["win32","volume","invalid-argument","jna"],"backgroundTag":"invalid-argument-format","analyzedSha":"d036ad9781adad4b66693e8fa7098e4ac665e0a3","analyzedAt":"2026-09-12T06:50:59.239Z","contentChangedAt":"2026-09-12T06:50:59.239Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}