Please read the FAQ, especially the question:
Why is my output wrong answer even though it looks identical to expected?
Right after your
char  out = new char[2 * L + 1];
I added this line of code:
for (int i = 0; i < 2*L+1; i++) out[i] = 'a';
And your code output becomes:
I guess that your code has one extra character, and since Java initialize it to
\0 by default, there is actually a non-printable character at the end, even though you don't see it.
PS: Unlike C/C++, Java does not need a null-terminated character for strings.