StringBuffer sb=null; // Some more logic that conditionally assigns value to the StringBuffer // Prints Value=null System.out.println(\"Value=\"+sb); // Throws Nu
System.out.print() is implemented like that:
public void print(String s) { if (s == null) { s = "null"; } write(s); }
With sb = null, sb.toString() means null.toString() which leads to you NullPointerException
sb.toString()
null.toString()