2727
2828import java .io .InputStream ;
2929import java .io .PrintStream ;
30- import java .lang .reflect .Field ;
3130
32- import com .oracle .svm .core .util .VMError ;
33- import com .oracle .svm .util .ReflectionUtil ;
34- import jdk .internal .access .SharedSecrets ;
3531import org .graalvm .nativeimage .ImageSingletons ;
3632import org .graalvm .nativeimage .hosted .Feature ;
3733
4440import com .oracle .svm .core .layeredimagesingleton .FeatureSingleton ;
4541import com .oracle .svm .hosted .imagelayer .CrossLayerConstantRegistry ;
4642
43+ import jdk .internal .access .SharedSecrets ;
44+
4745/**
4846 * We use an {@link Feature.DuringSetupAccess#registerObjectReplacer object replacer} because the
4947 * streams can be cached in other instance and static fields in addition to the fields in
@@ -64,18 +62,7 @@ public SystemInOutErrFeature() {
6462 hostedOut = wrappers .outWrapper ;
6563 hostedErr = wrappers .errWrapper ;
6664 hostedInitialIn = SharedSecrets .getJavaLangAccess ().initialSystemIn ();
67- /*
68- * GR-55515: Migrate to JavaLangAccess#initialSystemErr(). The method
69- * JavaLangAccess#initialSystemErr() and the System#initialErr field were both introduced in
70- * JDK 23. Once JDK 21 compatibility is no longer required, consider switching to
71- * SharedSecrets.getJavaLangAccess().initialSystemErr().
72- */
73- Field initialErrField = ReflectionUtil .lookupField (true , System .class , "initialErr" );
74- try {
75- hostedInitialErr = initialErrField != null ? (PrintStream ) initialErrField .get (null ) : null ;
76- } catch (IllegalAccessException illegalAccess ) {
77- throw VMError .shouldNotReachHere (illegalAccess );
78- }
65+ hostedInitialErr = SharedSecrets .getJavaLangAccess ().initialSystemErr ();
7966 }
8067
8168 private SystemInOutErrSupport runtime ;
0 commit comments