{"record":{"id":"43f10caa0f6c44bd","repo":"apereo/cas","slug":"no-authentication-event-has-been-recorded-cas-can","errorCode":null,"errorMessage":"No authentication event has been recorded; CAS cannot finalize the authentication result","messagePattern":"No authentication event has been recorded; CAS cannot finalize the authentication result","errorType":"console","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"core/cas-server-core-authentication-api/src/main/java/org/apereo/cas/authentication/DefaultAuthenticationResultBuilder.java","lineNumber":141,"sourceCode":"        authentications.forEach(authn -> {\n            mergePrincipalAttributes(principalAttributes, merger, authn);\n            mergeAuthenticationAttributes(authenticationAttributes, merger, authn);\n\n            authenticationBuilder\n                .addSuccesses(authn.getSuccesses())\n                .addFailures(authn.getFailures())\n                .addWarnings(authn.getWarnings())\n                .addCredentials(authn.getCredentials());\n        });\n    }\n\n    private boolean isEmpty() {\n        return this.authentications.isEmpty();\n    }\n\n    private @Nullable Authentication buildAuthentication(final PrincipalElectionStrategy principalElectionStrategy) throws Throwable {\n        if (isEmpty()) {\n            LOGGER.warn(\"No authentication event has been recorded; CAS cannot finalize the authentication result\");\n            return null;\n        }\n        val authenticationAttributes = new HashMap<String, List<Object>>();\n        val principalAttributes = new HashMap<String, List<Object>>();\n        val authenticationBuilder = DefaultAuthenticationBuilder.newInstance();\n\n        buildAuthenticationHistory(this.authentications, authenticationAttributes,\n            principalAttributes, authenticationBuilder, principalElectionStrategy);\n\n        synchronized (this.authentications) {\n            val primaryPrincipal = getPrimaryPrincipal(principalElectionStrategy, this.authentications, principalAttributes);\n            authenticationBuilder.setPrincipal(primaryPrincipal);\n        }\n        LOGGER.debug(\"Determined primary authentication principal to be [{}]\", authenticationBuilder.getPrincipal());\n\n        authenticationBuilder.setAttributes(authenticationAttributes);\n        LOGGER.trace(\"Collected authentication attributes for this result are [{}]\", authenticationAttributes);\n","sourceCodeStart":123,"sourceCodeEnd":159,"githubUrl":"https://github.com/apereo/cas/blob/e7288fc434b4f4505b8452e1a57e8fb3111bb863/core/cas-server-core-authentication-api/src/main/java/org/apereo/cas/authentication/DefaultAuthenticationResultBuilder.java#L123-L159","documentation":"In DefaultAuthenticationResultBuilder.buildAuthentication, if no authentication events were recorded at all, CAS logs this warning and returns null instead of fabricating an Authentication. Downstream this surfaces as a null authentication result when finalizing the flow.","triggerScenarios":"build(...) (via the authentication() method chain) invoked on a DefaultAuthenticationResultBuilder whose authentications list is empty — i.e. the authentication manager never ran or nothing was collected.","commonSituations":"Custom login flow bypassing the authentication manager; exception swallowed earlier so collection never happened; service/app integration calling build() on a freshly created builder in tests or extension code.","solutions":["Run the authentication manager and collect its result before calling build().","Check earlier flow steps for swallowed exceptions that skipped authentication collection.","Guard custom code against a null return from build() when authentications may be empty.","In tests, seed the builder with at least one Authentication."],"exampleFix":"// before\nval result = resultBuilder.build(principalElectionStrategy); // null\n// after\nval authentication = authenticationManager.authenticate(transaction);\nresultBuilder.collect(authentication);\nval result = resultBuilder.build(principalElectionStrategy);","handlingStrategy":"try-catch","validationCode":"if (resultBuilder.isEmpty() /* or authentications not collected */) {\n    throw new IllegalStateException(\"Cannot build result: no authentications collected\");\n}","typeGuard":"Authentication auth = resultBuilder.build(principalElectionStrategy);\nif (auth == null) {\n    // rerun authentication manager before finalizing\n}","tryCatchPattern":"try {\n    val result = resultBuilder.build(strategy);\n    if (result == null) {\n        LOGGER.error(\"Authentication result is null — no authentications recorded\");\n    }\n} catch (Throwable e) {\n    LOGGER.error(\"Failed to build authentication result\", e);\n}","preventionTips":["Never call build() on a freshly created builder in custom code or tests.","Log and handle null results where the builder may legitimately be empty."],"tags":["authentication","null-result","empty-state"],"backgroundTag":"empty-result-set","analyzedSha":"e7288fc434b4f4505b8452e1a57e8fb3111bb863","analyzedAt":"2026-09-08T15:39:16.015Z","contentChangedAt":"2026-09-08T15:39:16.015Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}