I just found a very strange NullPointerException . Firstly, I create such a NumberFormat (note that Locale will be Germany by default, I don't know if this helps):
NumberFormat angleFormat = NumberFormat.getNumberInstance(Locale.UK); angleFormat.setMaximumFractionDigits(5); angleFormat.setMinimumFractionDigits(0);
Then I tried to format double with it. This is done using a new thread created by Lambda, and angleFormat declared by the method containing Lambda. The code in which Exception is thrown is as follows:
con.println("D" + moveId + (state.isEnemyInSightOf(e) ? "+" : "-") + angleFormat.format(e.getAngle())
e.getAngle() returns a double , so it cannot return null. However, I get this exception:
Exception in thread "Thread-1" java.lang.NullPointerException at java.text.DecimalFormat.fastDoubleFormat(Unknown Source) at java.text.DecimalFormat.fastFormat(Unknown Source) at java.text.NumberFormat.format(Unknown Source) at server.game.Simulator.lambda$0(Simulator.java:123) at server.game.Simulator$$Lambda$3/23162747.run(Unknown Source) at java.lang.Thread.run(Unknown Source)
I am sure that e not null due to Exception stacktrace, it will a) be thrown one line earlier and b) not on java.text.DecimalFormat.fastDoubleFormat
Why is there a NullPointerException beeing throw sometimes , and sometimes it works without problems? And what does it mean? The error seems to be reproducible, but not very often.
msrd0 source share