StringBuffer sb=null; // Some more logic that conditionally assigns value to the StringBuffer // Prints Value=null System.out.println(\"Value=\"+sb); // Throws Nu
the exception is cause when sb.toString() gets executed.
In the fix you check if sb is null before executing so the offending call is not attempted.