This is pretty standard JNI code that sets System.out to the argument passed to it.

At first all this deal with setting System.out to nullPrintStream()
and later setting it with JNI seems entirely unnecessary. But this is
actually justified.

In Java, static fields are initialized first, and everything else
comes after. So even before the JVM and the System class is fully
initialized, the JVM tries to initialize System.out.

Unfortunately at this point the rest of the JVM isn’t properly
initialized so it’s impossible to reasonably set System.out at this
point. The best that could be done would be to set it to null.

The System class, along with System.out is properly initialized in
initializeSystemClass() which is called by the JVM after static and
thread initialization.

There is a problem, however. System.out is final, meaning we cannot
simply set it to something else in initializeSystemClass(). There’s a
way around that, however. Using native code, it is possible to modify a
final variable.