{"record":{"id":"89881ad41737ca10","repo":"apache/rocketmq","slug":"user-can-not-be-null","errorCode":null,"errorMessage":"user can not be null","messagePattern":"user can not be null","errorType":"exception","errorClass":"AuthenticationException","httpStatus":null,"severity":"error","filePath":"auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java","lineNumber":194,"sourceCode":"        } catch (Exception e) {\n            this.handleException(e, result);\n        }\n        return result;\n    }\n\n    @Override\n    public CompletableFuture<Boolean> isSuperUser(String username) {\n        return this.getUser(username).thenApply(user -> {\n            if (user == null) {\n                throw new AuthenticationException(\"User:{} is not found\", username);\n            }\n            return user.getUserType() == UserType.SUPER;\n        });\n    }\n\n    private void validate(User user, boolean isCreate) {\n        if (user == null) {\n            throw new AuthenticationException(\"user can not be null\");\n        }\n        if (StringUtils.isBlank(user.getUsername())) {\n            throw new AuthenticationException(\"username can not be blank\");\n        }\n        if (isCreate && StringUtils.isBlank(user.getPassword())) {\n            throw new AuthenticationException(\"password can not be blank\");\n        }\n    }\n\n    private void handleException(Exception e, CompletableFuture<?> result) {\n        Throwable throwable = ExceptionUtils.getRealException(e);\n        result.completeExceptionally(throwable);\n    }\n\n    private AuthenticationMetadataProvider getAuthenticationMetadataProvider() {\n        if (authenticationMetadataProvider == null) {\n            throw new IllegalStateException(\"The authenticationMetadataProvider is not configured.\");\n        }","sourceCodeStart":176,"sourceCodeEnd":212,"githubUrl":"https://github.com/apache/rocketmq/blob/293f5885719fc4aa3619446a1900f58ccfcfdd29/auth/src/main/java/org/apache/rocketmq/auth/authentication/manager/AuthenticationMetadataManagerImpl.java#L176-L212","documentation":"Shared validator used by createUser/updateUser rejected a null User object before touching the metadata store. Indicates a programming error at the call site - the API contract requires an actual User, not null.","triggerScenarios":"Calling createUser(null) or updateUser(null), typically because a mapper/builder returned null (failed parse, missing DTO fields) or a variable was never assigned.","commonSituations":"RPC layer deserializing an absent body into null; optional-based flows calling .orElse(null); test code exercising edge cases.","solutions":["Construct and pass a valid User (username required; password required for create).","Add null/Optional guards at the API boundary so a null never reaches the manager.","If deserialization can yield null, map it to a 400-style validation error instead of calling the manager."],"exampleFix":"// before\nauthManager.createUser(maybeUser); // maybeUser is null when JSON body absent\n\n// after\nUser user = Optional.ofNullable(maybeUser).orElseThrow(() -> new IllegalArgumentException(\"user body required\"));\nauthManager.createUser(user);","handlingStrategy":"type-guard","validationCode":"if (user == null) throw new IllegalArgumentException(\"user payload required\");\nauthManager.createUser(user);","typeGuard":"boolean isCreatable(User u) { return u != null && u.getUsername() != null && !u.getUsername().trim().isEmpty() && u.getPassword() != null && !u.getPassword().isEmpty(); }","tryCatchPattern":"catch (AuthenticationException e) { if message contains \"user can not be null\" -> fix deserialization/builder at the caller; permanent bug, do not retry. }","preventionTips":["Map absent request bodies to explicit 400s at the controller layer","Avoid Optional.orElse(null) patterns feeding managers"],"tags":["rocketmq","user-management","validation","null-check"],"backgroundTag":null,"analyzedSha":"293f5885719fc4aa3619446a1900f58ccfcfdd29","analyzedAt":"2026-08-14T11:50:13.822Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}