czwartek, maja 18, 2017

Bug in Java(c)?

String lastReturnCode = "WAITING";
Long isSuccessful = ("OK".equals(lastReturnCode) || "DEAD".equals(lastReturnCode)) ? 1L :
 "WAITING".equals(lastReturnCode) ? null : 0L;
System.out.println(isSuccessful);

NullPointerException in the third line. Let's decompile class file.
Long isSuccessful = Long.valueOf((("OK".equals(lastReturnCode)) || ("DEAD".equals(lastReturnCode))) ? 1L : 
(("WAITING".equals(lastReturnCode)) ? null : Long.valueOf(0L))
.longValue());

No proper autoboxing here. Use Long.valueOf(1L) to fix it.

0 komentarze: