@@ -191,8 +191,9 @@ private System() {
191191 */
192192 public static final PrintStream err = null ;
193193
194- // Holder for the initial value of `in`, set within `initPhase1()`.
195- private static InputStream initialIn ;
194+ // Initial values of System.in and System.err, set in initPhase1().
195+ private static @ Stable InputStream initialIn ;
196+ private static @ Stable PrintStream initialErr ;
196197
197198 // indicates if a security manager is possible
198199 private static final int NEVER = 1 ;
@@ -355,9 +356,6 @@ private static class CallersHolder {
355356 = Collections .synchronizedMap (new WeakHashMap <>());
356357 }
357358
358- // Remember initial System.err. setSecurityManager() warning goes here
359- private static volatile @ Stable PrintStream initialErrStream ;
360-
361359 private static URL codeSource (Class <?> clazz ) {
362360 PrivilegedAction <ProtectionDomain > pa = clazz ::getProtectionDomain ;
363361 @ SuppressWarnings ("removal" )
@@ -417,7 +415,7 @@ public static void setSecurityManager(@SuppressWarnings("removal") SecurityManag
417415 } else {
418416 source = callerClass .getName () + " (" + url + ")" ;
419417 }
420- initialErrStream .printf ("""
418+ initialErr .printf ("""
421419 WARNING: A terminally deprecated method in java.lang.System has been called
422420 WARNING: System::setSecurityManager has been called by %s
423421 WARNING: Please consider reporting this to the maintainers of %s
@@ -2200,7 +2198,8 @@ private static void initPhase1() {
22002198 // thus they are equivalent to Console.charset(), otherwise the encodings
22012199 // of those properties default to native.encoding
22022200 setOut0 (newPrintStream (fdOut , props .getProperty ("stdout.encoding" )));
2203- setErr0 (newPrintStream (fdErr , props .getProperty ("stderr.encoding" )));
2201+ initialErr = newPrintStream (fdErr , props .getProperty ("stderr.encoding" ));
2202+ setErr0 (initialErr );
22042203
22052204 // Setup Java signal handlers for HUP, TERM, and INT (where available).
22062205 Terminator .setup ();
@@ -2406,8 +2405,6 @@ private static void initPhase3() {
24062405 notSupportedJnuEncoding );
24072406 }
24082407
2409- initialErrStream = System .err ;
2410-
24112408 // initializing the system class loader
24122409 VM .initLevel (3 );
24132410
@@ -2598,6 +2595,10 @@ public InputStream initialSystemIn() {
25982595 return initialIn ;
25992596 }
26002597
2598+ public PrintStream initialSystemErr () {
2599+ return initialErr ;
2600+ }
2601+
26012602 public void setCause (Throwable t , Throwable cause ) {
26022603 t .setCause (cause );
26032604 }
0 commit comments