apache/shenyu · error · NullPointerException
accessToken is null
Error message
accessToken is null
What it means
HttpClientRegisterRepository.doRegister looks up the cached access token for each admin server before sending a register request; if no token has been stored for that server URL (blank/null map entry) it deliberately throws NullPointerException. The token is normally obtained during the login/handshake phase, so a missing token means the client never authenticated with that admin node.
Solutions
- Verify shenyu.register.http.username/password (or accessToken) config matches the admin credentials
- Check client logs for the earlier login failure against that admin server
- Ensure the admin server URL in serverLists is correct and reachable
- Restart the client so the auth/login handshake re-runs before registering
Example fix
// before
shenyu:
register:
serverLists: http://admin1:9095,http://admin2:9095
# credentials missing -> accessToken never populated
// after
shenyu:
register:
serverLists: http://admin1:9095,http://admin2:9095
username: admin
password: admin Defensive patterns
Strategy: validation
Validate before calling
String token = accessTokenMap.get(server); if (token == null || token.isBlank()) { reAuthenticate(server); } Try / catch
try { repository.doRegister(dto); } catch (Exception e) { log.error("register failed, token/auth issue: {}", e.getMessage()); scheduleRetry(); } Prevention
- Always configure register username/password matching admin
- Check client startup logs for successful login before services register
- Keep serverLists limited to reachable admin nodes
When it happens
Trigger: doRegister invoked (via doPersistURI/doPersistApiDoc/doPersistInterface/doPersistMcpTools/closeRepository/doPersistDiscoveryConfig) before the per-server access token was populated, e.g. login failed, wrong username/password/token config, or the server entry in shenyu.register.serverLists was never contacted successfully.
Common situations: Misconfigured shenyu.register.serverLists containing an admin node that never completed login; wrong credentials in shenyu.register.http.username/password; clock/token expiry clearing the map before first register; client registration racing startup before authentication completes.
Related errors
- accessToken is null
- dynamic: result.getMessage() from…
- group param invalid
- websocket sync token is invalid
- Failed to get Swagger document, HTTP status code:
AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12).
Data as JSON: /api/errors/365c8f67a794abd5.
Report an issue: GitHub.
Appendix: source
Thrown at shenyu-register-center/shenyu-register-client/shenyu-register-client-http/src/main/java/org/apache/shenyu/register/client/http/HttpClientRegisterRepository.java:199
/**
* doPersistDiscoveryConfig.
*
* @param discoveryConfigRegisterDTO discoveryConfigRegisterDTO
*/
public void doPersistDiscoveryConfig(final DiscoveryConfigRegisterDTO discoveryConfigRegisterDTO) {
doRegister(discoveryConfigRegisterDTO, Constants.DISCOVERY_CONFIG_PATH, Constants.DISCOVERY_CONFIG_TYPE);
}
private <T> void doRegister(final T t, final String path, final String type) {
int i = 0;
for (String server : serverList) {
i++;
String concat = server.concat(path);
try {
String accessToken = this.accessToken.get(server);
if (StringUtils.isBlank(accessToken)) {
throw new NullPointerException("accessToken is null");
}
RegisterUtils.doRegister(GsonUtils.getInstance().toJson(t), concat, type, accessToken);
// considering the situation of multiple clusters, we should continue to execute here
} catch (Exception e) {
LOGGER.error("Register admin url :{} is fail, will retry. cause:{}", server, e.getMessage());
if (i == serverList.size()) {
throw new RuntimeException(e);
}
}
}
}
private <T> void doHeartbeat(final T t, final String path) {
int i = 0;
for (String server : serverList) {
i++;
String concat = server.concat(path);
try {View on GitHub (pinned to 567142e072)