# Elasticsearch-migrate returns java NullPointer error

**URL:** <https://discuss.elastic.co/t/elasticsearch-migrate-returns-java-nullpointer-error/289129>\
**Category:** Elasticsearch\
**Tags:** elastic-stack-security\
**Created:** [November 13, 2021, 10:06pm UTC](https://discuss.elastic.co/t/elasticsearch-migrate-returns-java-nullpointer-error/289129 "2021-11-13T22:06:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![bchill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bchill/32/97089_2.png) [@bchill](https://discuss.elastic.co/u/bchill)\
**Post date:** [November 13, 2021, 10:06pm UTC](https://discuss.elastic.co/t/elasticsearch-migrate-returns-java-nullpointer-error/289129/1 "2021-11-13T22:06:52Z")

</div>

Hello,

I am getting a java error when using Elasticsearch-migrate. I realize this tool is deprecated and don't expect help.

To simplify the problem, I emptied the users file and created a single user, 'joe', with password 'joejoe' using the Elasticsearch-users tool (useradd mode), which worked fine:

```auto
# ls -l users
-rw-rw---- 1 root elasticsearch 65 Nov 13 16:56 users
# cat users
joe:$2a$08$m29sz92MBXNQsXttclp2dO6MlBQvgVyXUueGU.VdQ4xMgMdrxOuBO

```

.... Elasticsearch-migrate does not:

```auto
# elasticsearch-migrate native -u elastic -p XXXXX -U https://myhost:9200
Warning: The migrate tool is deprecated. Use the native realm directly instead of file realms.
starting migration of users and roles...
importing users from [/etc/elasticsearch/users]...
found existing users: [apm_system, logstash_system, beats_system, remote_monitoring_user, elastic, kibana_system, kibana, bchill]
migrating user [joe]
Exception in thread "main" ElasticsearchException[failed to migrate user [joe] with body: n/a]; nested: NullPointerException;
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.importUsers(ESNativeRealmMigrateTool.java:284)
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.execute(ESNativeRealmMigrateTool.java:139)
	at org.elasticsearch.cli.EnvironmentAwareCommand.execute(EnvironmentAwareCommand.java:75)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:114)
	at org.elasticsearch.cli.MultiCommand.execute(MultiCommand.java:95)
	at org.elasticsearch.cli.Command.mainWithoutErrorHandling(Command.java:114)
	at org.elasticsearch.cli.Command.main(Command.java:79)
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool.main(ESNativeRealmMigrateTool.java:80)
Caused by: java.lang.NullPointerException
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.createUserJson(ESNativeRealmMigrateTool.java:235)
	at org.elasticsearch.xpack.security.authc.esnative.ESNativeRealmMigrateTool$MigrateUserOrRoles.importUsers(ESNativeRealmMigrateTool.java:279)
	... 7 more

```

The basic communication seems to work, since it does find the existing users.

The Elasticsearch log (/var/log/Elasticsearch.log) only shows this new entry:

`[2021-11-13T16:56:36,318][INFO][o.e.x.s.a.f.FileUserPasswdStore] [myhost] users file [/etc/elasticsearch/users] changed. updating users...`

system/software details:

```auto
# echo $ES_JAVA_HOME
/usr/lib/jvm/java-11-openjdk
# rpm -q elasticsearch
elasticsearch-7.15.1-1.x86_64
# cat /etc/centos-release
CentOS Linux release 7.9.2009 (Core)

```

Am I missing something obvious?

---

<div class="post-metadata">

**Author:** ![Yang\_Wang](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yang_wang/32/48857_2.png) [@Yang\_Wang](https://discuss.elastic.co/u/Yang_Wang)\
**Post date:** [November 14, 2021, 11:37pm UTC](https://discuss.elastic.co/t/elasticsearch-migrate-returns-java-nullpointer-error/289129/2 "2021-11-14T23:37:36Z")

</div>

This is because user `joe` does not have any roles. You need assign some roles to `joe` in the `$CONFIG/users_roles` file. Alternatively you can delete the user and re-create with roles, e.g.:

```auto
./bin/elasticsearch-users userdel joe
./bin/elasticsearch-users useradd joe -r SOME_ROLE

```

---

<div class="post-metadata">

**Author:** ![bchill](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bchill/32/97089_2.png) [@bchill](https://discuss.elastic.co/u/bchill)\
**Post date:** [November 15, 2021, 7:21am UTC](https://discuss.elastic.co/t/elasticsearch-migrate-returns-java-nullpointer-error/289129/3 "2021-11-15T07:21:19Z")

</div>

That worked. I guess I stumbled over a bug in a deprecated tool. 🙂

Thanks!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 13, 2021, 7:22am UTC](https://discuss.elastic.co/t/elasticsearch-migrate-returns-java-nullpointer-error/289129/4 "2021-12-13T07:22:02Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
