Your assumption is incorrect. Why?
Because function parameters are always passed-by-value.
When you do:
buffer = new StringBuffer(buffer.substring(i));
you are assigning a new StringBuffer
to a local reference that was copied from the parameter reference. So, the original buffer doesn't change.