1

I'm trying the elasticsearch Java API. And I got this error :

java.lang.NullPointerException
at java.io.Reader.<init>(Reader.java:78)
at java.io.InputStreamReader.<init>(InputStreamReader.java:113)
at org.elasticsearch.node.internal.InternalSettingsPreparer.randomNodeName(InternalSettingsPreparer.java:198)
at org.elasticsearch.node.internal.InternalSettingsPreparer.finalizeSettings(InternalSettingsPreparer.java:177)
at org.elasticsearch.node.internal.InternalSettingsPreparer.prepareSettings(InternalSettingsPreparer.java:64)
at org.elasticsearch.client.transport.TransportClient$Builder.build(TransportClient.java:119)
at TryElastic.main(TryElastic.java:64)

So, how can I get the error cause? It only said that it's an null pointer error. The only file that I can open and edit is my file "TryElastic.java". I want to know, what cause java.io.Reader error. I need your suggest, Thanks...

Kenny Basuki
  • 625
  • 4
  • 11
  • 27
  • Well, look at line 64 in "TryElastic.java". What line is it? – Seelenvirtuose Feb 21 '16 at 09:30
  • `at TryElastic.main(TryElastic.java:64)` -- Indicates that you have error at line number 64 where you are doing some operation which is causing null pointer exception. – sandip Feb 21 '16 at 09:32
  • 1
    The most efficient way - you should use debugging on your program with breakpoint on `TryElastic` class on 64th line. Starting this line you should go deeper and find out why is `null` were provided to `InputStreamReader` as parameter of constructor (Possibly you haven't some file or some wrong in sources that defines what will be passed as parameter for constructor) – Pavel Uvarov Feb 21 '16 at 09:40

1 Answers1

0

If you look at the source of the method which probably causes the NPE

https://github.com/elastic/elasticsearch/blob/master/core/src/main/java/org/elasticsearch/node/internal/InternalSettingsPreparer.java#L172

you see that it is trying to load a resource /config/names.txt which obviously returns null and triggers the NPE in the Reader constructor. (Stracktrace line numbers do not match exactly due to different versions used). Unfortunately Elastic does not check the resource stream - it really should raise an own exception with a better error message.

So to solve the problem you should check if that resource is available in your installation.

wero
  • 32,544
  • 3
  • 59
  • 84