{"record":{"id":"e797a750543945b9","repo":"java-native-access/jna","slug":"invalid-guid-length","errorCode":null,"errorMessage":"Invalid guid length: ","messagePattern":"Invalid guid length: ","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"contrib/platform/src/com/sun/jna/platform/win32/Guid.java","lineNumber":261,"sourceCode":"        }\n\n        /**\n         * From string.\n         *\n         * @param guid\n         *            the guid\n         * @return the guid\n         */\n        public static GUID fromString(String guid) {\n            int y = 0;\n            char[] _cnewguid = new char[32];\n            char[] _cguid = guid.toCharArray();\n            byte[] bdata = new byte[16];\n            GUID newGuid = new GUID();\n\n            // we not accept a string longer than 38 chars\n            if (guid.length() > 38) {\n                throw new IllegalArgumentException(\"Invalid guid length: \"\n                        + guid.length());\n            }\n\n            // remove '{', '}' and '-' from guid string\n            for (int i = 0; i < _cguid.length; i++) {\n                if ((_cguid[i] != '{') && (_cguid[i] != '-')\n                        && (_cguid[i] != '}'))\n                    _cnewguid[y++] = _cguid[i];\n            }\n\n            // convert char to byte\n            for (int i = 0; i < 32; i += 2) {\n                bdata[i / 2] = (byte) ((Character.digit(_cnewguid[i], 16) << 4)\n                        + Character.digit(_cnewguid[i + 1], 16) & 0xff);\n            }\n\n            if (bdata.length != 16) {\n                throw new IllegalArgumentException(\"Invalid data length: \"","sourceCodeStart":243,"sourceCodeEnd":279,"githubUrl":"https://github.com/java-native-access/jna/blob/d036ad9781adad4b66693e8fa7098e4ac665e0a3/contrib/platform/src/com/sun/jna/platform/win32/Guid.java#L243-L279","documentation":"GUID.fromString throws this IllegalArgumentException when the string representation of the GUID is longer than 38 characters (the maximum length of the '{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}' form). Longer inputs cannot be a valid GUID string.","triggerScenarios":"Passing a full IID string with extra whitespace/prefix, a base64 or hex-dumped GUID (e.g. 32-byte string), or concatenating GUIDs/typo (duplicate paste) into fromString.","commonSituations":"Reading identifiers from registry/config that include a prefix like 'CLSID\\{...}' or trailing data; accidentally passing a byte-hex dump of two GUIDs; UI copy including surrounding text.","solutions":["Trim and strip surrounding text so only the 38-char '{...-...}' form (or 32/36-char variant) remains","Extract the GUID with a regex like \\{?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\\}? before parsing","If the input is a raw hex string without dashes/braces, ensure it is exactly 32 hex chars"],"exampleFix":"// before\nGUID g = GUID.fromString(regValue); // \"CLSID\\{6B29...}-extra\"\n// after\njava.util.regex.Matcher m = java.util.regex.Pattern\n    .compile(\"\\\\{?[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}\\\\}?\")\n    .matcher(regValue);\nGUID g = m.find() ? GUID.fromString(m.group()) : null;","handlingStrategy":"validation","validationCode":"String s = raw.trim();\nif (s.length() > 38)\n    throw new IllegalArgumentException(\"Not a GUID string (len \" + s.length() + \"): \" + raw);\nGUID g = GUID.fromString(s);","typeGuard":"boolean isGuidShape(String s) {\n    return s != null && s.length() <= 38 && s.matches(\"\\\\{?[0-9a-fA-F]{8}-([0-9a-fA-F]{4}-){3}[0-9a-fA-F]{12}\\\\}?\");\n}","tryCatchPattern":"try {\n    GUID g = GUID.fromString(input);\n} catch (IllegalArgumentException e) {\n    // strip surrounding text or extract via regex, then retry\n    java.util.regex.Matcher m = GUID_RX.matcher(input);\n    GUID g = m.find() ? GUID.fromString(m.group()) : null;\n}","preventionTips":["Trim strings and strip prefixes/suffixes (e.g. 'CLSID\\\\{...}', registry names) before parsing","Extract with a GUID regex when input comes from free-form sources","Use GUID.fromStringIID for '{...}' IID literals to get stricter parsing"],"tags":["java","win32","guid","string-parsing","validation"],"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-14T11:17:12.474Z"}