{"record":{"id":"efc2401f5d5d1a1f","repo":"spring-projects/spring-security","slug":"error-while-invoking-method-methodclass-methodn","errorCode":null,"errorMessage":"Error while invoking method <methodClass>.<methodName>(<args>)","messagePattern":"Error while invoking method <methodClass>\\.<methodName>\\(<args>\\)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"web/src/main/java/org/springframework/security/web/authentication/preauth/websphere/DefaultWASUsernameAndGroupsExtractor.java","lineNumber":163,"sourceCode":"\t\ttry {\n\t\t\tif (context != null) {\n\t\t\t\tcontext.close();\n\t\t\t}\n\t\t}\n\t\tcatch (NamingException ex) {\n\t\t\tlogger.debug(\"Exception occurred while closing context\", ex);\n\t\t}\n\t}\n\n\tprivate static Object invokeMethod(Method method, @Nullable Object instance, Object... args) {\n\t\ttry {\n\t\t\treturn method.invoke(instance, args);\n\t\t}\n\t\tcatch (IllegalArgumentException | IllegalAccessException | InvocationTargetException ex) {\n\t\t\tString message = \"Error while invoking method \" + method.getClass().getName() + \".\" + method.getName() + \"(\"\n\t\t\t\t\t+ Arrays.asList(args) + \")\";\n\t\t\tlogger.error(message, ex);\n\t\t\tthrow new RuntimeException(message, ex);\n\t\t}\n\t}\n\n\tprivate static Method getMethod(String className, String methodName, String[] parameterTypeNames) {\n\t\ttry {\n\t\t\tClass<?> c = Class.forName(className);\n\t\t\tint len = parameterTypeNames.length;\n\t\t\tClass<?>[] parameterTypes = new Class[len];\n\t\t\tfor (int i = 0; i < len; i++) {\n\t\t\t\tparameterTypes[i] = Class.forName(parameterTypeNames[i]);\n\t\t\t}\n\t\t\treturn c.getDeclaredMethod(methodName, parameterTypes);\n\t\t}\n\t\tcatch (ClassNotFoundException ex) {\n\t\t\tlogger.error(\"Required class\" + className + \" not found\");\n\t\t\tthrow new RuntimeException(\"Required class\" + className + \" not found\", ex);\n\t\t}\n\t\tcatch (NoSuchMethodException ex) {","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/spring-projects/spring-security/blob/96852e8860138a482cb13d1479573f24ff6443c6/web/src/main/java/org/springframework/security/web/authentication/preauth/websphere/DefaultWASUsernameAndGroupsExtractor.java#L145-L181","documentation":"invokeMethod wraps reflective Method.invoke calls used to access WebSphere internal APIs (WSSubject, WASCredential, etc.). If the reflection call fails with IllegalArgumentException, IllegalAccessException, or InvocationTargetException, the exception is logged and rethrown as a RuntimeException whose message includes the target class, method and argument list. This indicates the WebSphere runtime API could not be invoked as expected.","triggerScenarios":"Any reflective invocation made by getSecurityName, getRunAsSubject, userReg, or groups when: the target method itself throws (InvocationTargetException - e.g. WAS internal error), the method is inaccessible (IllegalAccessException - non-public on a restricted classloader), or the argument types/values do not match the method signature (IllegalArgumentException).","commonSituations":"Running on a WebSphere version where the internal API changed signature; invoking with a null/incorrectly-typed subject or credential; calling a private method without setAccessible success under a restrictive SecurityManager; WAS fixpack altering internal class behavior.","solutions":["Read the cause chain: for InvocationTargetException, unwrap ex.getCause() to see the real WAS-side failure.","Verify the WebSphere version matches the API signatures this extractor was built against; upgrade spring-security-web or adjust for your WAS release.","Ensure the code runs inside the WAS container with a valid WSSubject/RunAs subject present (e.g. inside an authenticated request thread).","Check for a SecurityManager or classloader restriction blocking access to the method; relax setAccessible or run the call in a privileged block.","If arguments were supplied programmatically, validate their types match the declared parameter types before invoking."],"exampleFix":"// before\nString name = extractor.getSecurityName(subject);\n// after\nString name;\ntry {\n    name = extractor.getSecurityName(subject);\n} catch (RuntimeException ex) {\n    logger.error(\"WAS reflection invoke failed: \" + ex.getCause(), ex);\n    throw new AuthenticationServiceException(\"WebSphere security name lookup failed\", ex);\n}","handlingStrategy":"try-catch","validationCode":"// confirm the WAS API method exists before invoking reflectively\ntry {\n    Class.forName(\"com.ibm.websphere.security.auth.WSSubject\");\n} catch (ClassNotFoundException e) {\n    throw new IllegalStateException(\"WebSphere runtime not present\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    String name = extractor.getSecurityName(subject);\n} catch (RuntimeException ex) {\n    // InvocationTargetException: unwrap ex.getCause() for the WAS-side error\n    // IllegalArgument/IllegalAccess: signature or access problem\n    logger.error(\"WAS reflective invoke failed: \" + ex.getMessage(), ex.getCause());\n    throw new AuthenticationServiceException(\"WebSphere security lookup failed\", ex);\n}","preventionTips":["Keep spring-security-web version aligned with your WebSphere server version","Never invoke with null or wrongly-typed subject/credential objects","Check for SecurityManager/classloader restrictions before reflective access","Always inspect the wrapped cause - InvocationTargetException hides the real WAS error"],"tags":["reflection","websphere","invoke","runtime-exception"],"backgroundTag":"class-not-found","analyzedSha":"96852e8860138a482cb13d1479573f24ff6443c6","analyzedAt":"2026-09-10T23:25:23.477Z","contentChangedAt":"2026-09-10T23:25:23.477Z","schemaVersion":2},"datasetVersion":"2026-09-14T11:17:12.474Z"}