There is nothing wrong with your Singleton. There are no concurrency problems because this is not multithreaded code.
You were thinking s
was null, but it is really i
that was null.
Since addToLevel
takes an int
as a parameter, the Integer i
was autounboxed (implicitly converted from Integer
to int
), but since i
was null
, NullPointerException
was thrown. Autounboxing throws NullPointerException
when the value being coverted is null
.
The reason Integer.getInteger(Singleton.K_LEVEL)
returned null
is because you did java A -Dlevel=1
as opposed to java -Dlevel=1 A
. The latter is the correct syntax.