# Occurrence of NullPointerException and role not assigned when using elasticsearch-users command in Windows

**URL:** <https://discuss.elastic.co/t/occurrence-of-nullpointerexception-and-role-not-assigned-when-using-elasticsearch-users-command-in-windows/361280>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security, windows\
**Created:** [June 11, 2024, 4:13pm UTC](https://discuss.elastic.co/t/occurrence-of-nullpointerexception-and-role-not-assigned-when-using-elasticsearch-users-command-in-windows/361280 "2024-06-11T16:13:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mousumis](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@mousumis](https://discuss.elastic.co/u/mousumis)\
**Post date:** [June 11, 2024, 4:13pm UTC](https://discuss.elastic.co/t/occurrence-of-nullpointerexception-and-role-not-assigned-when-using-elasticsearch-users-command-in-windows/361280/1 "2024-06-11T16:13:23Z")

</div>

I am attempting to use the `elasticsearch-users.bat` utility on a windows machine (Windows Server 2022) to create a user. I am running the following command:  
`elasticsearch-users.bat useradd admin_user -p "testpassword" -r superuser`

After running this, I observe the following:

1. There is a null pointer exception thrown, though I believe the user is created.

```auto
Exception in thread "main" java.lang.NullPointerException: Cannot invoke "java.util.Map.size()" because "m" is null
        at java.base/java.util.HashMap.putMapEntries(HashMap.java:495)
        at java.base/java.util.HashMap.<init>(HashMap.java:484)
        at org.elasticsearch.xpack.security.authc.file.tool.UsersTool$AddUserCommand.execute(UsersTool.java:137)
        at org.elasticsearch.common.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:54)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
        at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:94)
        at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:85)
        at org.elasticsearch.cli.Command.main(Command.java:50)
        at org.elasticsearch.launcher.CliToolLauncher.main(CliToolLauncher.java:64)

```

I have also tried other commands like `userdel` and `roles` with `elasticsearch-users.bat` and they all cause the NullPointerException. I saw a somewhat related [post](https://discuss.elastic.co/t/elastic-endpoint-filebeat-java-error/282676) but it does not appear to have a resolution.

1. Subsequent attempts to call elasticsearch endpoints with this user are rejected, though I tried to assign the `superuser` role when creating the user.

```auto
bin>curl -i -X POST -u "admin_user:testpassword" -H "Content-Type: application/json" -d"{\"cluster\": [\"monitor\"]}" localhost:9200/_security/role/health_check_role

HTTP/1.1 403 Forbidden
content-type: application/json
content-length: 485

{"error":{"root_cause":[{"type":"security_exception","reason":"action [cluster:admin/xpack/security/role/put] is unauthorized for user [appian_admin] with effective roles [], this action is granted by the cluster privileges [manage_security,all]"}],"type":"security_exception","reason":"action [cluster:admin/xpack/security/role/put] is unauthorized for user [appian_admin] with effective roles [], this action is granted by the cluster privileges [manage_security,all]"},"status":403}

```

I would appreciate any insight into why the error is occurring, why the role assignment is not taking effect for the user, and if there are any steps I am missing.

---

<div class="post-metadata">

**Author:** ![TimV](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/timv/32/13162_2.png) [@TimV](https://discuss.elastic.co/u/TimV)\
**Post date:** [June 12, 2024, 3:19am UTC](https://discuss.elastic.co/t/occurrence-of-nullpointerexception-and-role-not-assigned-when-using-elasticsearch-users-command-in-windows/361280/2 "2024-06-12T03:19:19Z")

</div>

It looks like your `users_roles` file is missing which causes the users command to fail.

Check for a file named `users_roles` in your config directory (the same directory where your `elasticsearch.yml` is).  
If it's not there, then you should create it as an empty file.  
If it is there, then you might have a permissions problem, or your `elasticsearch-users` tool might be configured to look in the wrong directory.

---

<div class="post-metadata">

**Author:** ![mousumis](https://avatars.discourse-cdn.com/v4/letter/m/53a042/32.png) [@mousumis](https://discuss.elastic.co/u/mousumis)\
**Post date:** [June 16, 2024, 8:07pm UTC](https://discuss.elastic.co/t/occurrence-of-nullpointerexception-and-role-not-assigned-when-using-elasticsearch-users-command-in-windows/361280/3 "2024-06-16T20:07:12Z")

</div>

Yes that was the issue, the error threw me off. Thank you for your help!
