Skip to content

Commit e344f3f

Browse files
committed
Consistent treatment of new Spring system properties
See gh-30606 See gh-30571
1 parent 517a073 commit e344f3f

File tree

2 files changed

+18
-12
lines changed

2 files changed

+18
-12
lines changed

spring-context/src/main/java/org/springframework/context/support/DefaultLifecycleProcessor.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
7070
/**
7171
* Property name for a common context checkpoint: {@value}.
7272
* @since 6.1
73-
* @see #CHECKPOINT_ON_REFRESH
73+
* @see #CHECKPOINT_ON_REFRESH_VALUE
7474
* @see org.crac.Core#checkpointRestore()
7575
*/
7676
public static final String CHECKPOINT_PROPERTY_NAME = "spring.context.checkpoint";
@@ -81,11 +81,11 @@ public class DefaultLifecycleProcessor implements LifecycleProcessor, BeanFactor
8181
* @see #CHECKPOINT_PROPERTY_NAME
8282
* @see org.crac.Core#checkpointRestore()
8383
*/
84-
public static final String CHECKPOINT_ON_REFRESH = "onRefresh";
84+
public static final String CHECKPOINT_ON_REFRESH_VALUE = "onRefresh";
8585

8686

87-
private final static boolean checkpointRestoreOnRefresh = CHECKPOINT_ON_REFRESH.equalsIgnoreCase(
88-
SpringProperties.getProperty(CHECKPOINT_PROPERTY_NAME));
87+
private final static boolean checkpointOnRefresh =
88+
CHECKPOINT_ON_REFRESH_VALUE.equalsIgnoreCase(SpringProperties.getProperty(CHECKPOINT_PROPERTY_NAME));
8989

9090
private final Log logger = LogFactory.getLog(getClass());
9191

@@ -169,7 +169,7 @@ public void stop() {
169169

170170
@Override
171171
public void onRefresh() {
172-
if (checkpointRestoreOnRefresh) {
172+
if (checkpointOnRefresh) {
173173
new CracDelegate().checkpointRestore();
174174
}
175175

spring-core/src/main/java/org/springframework/aot/nativex/feature/PreComputeFieldFeature.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,8 @@
3636
*/
3737
class PreComputeFieldFeature implements Feature {
3838

39-
private static final boolean verbose = "verbose".equals(System.getProperty("spring.native.precompute.log"));
39+
private static final boolean verbose =
40+
"verbose".equalsIgnoreCase(System.getProperty("spring.native.precompute.log"));
4041

4142
private static final Pattern[] patterns = {
4243
Pattern.compile(Pattern.quote("org.springframework.core.NativeDetector#inNativeImage")),
@@ -48,14 +49,15 @@ class PreComputeFieldFeature implements Feature {
4849
Pattern.compile(Pattern.quote("org.apache.commons.logging.LogAdapter") + "#.*Present")
4950
};
5051

51-
private final ThrowawayClassLoader throwawayClassLoader = new ThrowawayClassLoader(PreComputeFieldFeature.class.getClassLoader());
52+
private final ThrowawayClassLoader throwawayClassLoader = new ThrowawayClassLoader(getClass().getClassLoader());
53+
5254

5355
@Override
5456
public void beforeAnalysis(BeforeAnalysisAccess access) {
5557
access.registerSubtypeReachabilityHandler(this::iterateFields, Object.class);
5658
}
5759

58-
/* This method is invoked for every type that is reachable. */
60+
// This method is invoked for every type that is reachable.
5961
private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
6062
try {
6163
for (Field field : subtype.getDeclaredFields()) {
@@ -71,12 +73,14 @@ private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
7173
Object fieldValue = provideFieldValue(field);
7274
access.registerFieldValueTransformer(field, (receiver, originalValue) -> fieldValue);
7375
if (verbose) {
74-
System.out.println("Field " + fieldIdentifier + " set to " + fieldValue + " at build time");
76+
System.out.println(
77+
"Field " + fieldIdentifier + " set to " + fieldValue + " at build time");
7578
}
7679
}
7780
catch (Throwable ex) {
7881
if (verbose) {
79-
System.out.println("Field " + fieldIdentifier + " will be evaluated at runtime due to this error during build time evaluation: " + ex.getMessage());
82+
System.out.println("Field " + fieldIdentifier + " will be evaluated at runtime " +
83+
"due to this error during build time evaluation: " + ex);
8084
}
8185
}
8286
}
@@ -88,8 +92,10 @@ private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
8892
}
8993
}
9094

91-
/* This method is invoked when the field value is written to the image heap or the field is constant folded. */
92-
private Object provideFieldValue(Field field) throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
95+
// This method is invoked when the field value is written to the image heap or the field is constant folded.
96+
private Object provideFieldValue(Field field)
97+
throws ClassNotFoundException, NoSuchFieldException, IllegalAccessException {
98+
9399
Class<?> throwawayClass = this.throwawayClassLoader.loadClass(field.getDeclaringClass().getName());
94100
Field throwawayField = throwawayClass.getDeclaredField(field.getName());
95101
throwawayField.setAccessible(true);

0 commit comments

Comments
 (0)