36
36
*/
37
37
class PreComputeFieldFeature implements Feature {
38
38
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" ));
40
41
41
42
private static final Pattern [] patterns = {
42
43
Pattern .compile (Pattern .quote ("org.springframework.core.NativeDetector#inNativeImage" )),
@@ -48,14 +49,15 @@ class PreComputeFieldFeature implements Feature {
48
49
Pattern .compile (Pattern .quote ("org.apache.commons.logging.LogAdapter" ) + "#.*Present" )
49
50
};
50
51
51
- private final ThrowawayClassLoader throwawayClassLoader = new ThrowawayClassLoader (PreComputeFieldFeature .class .getClassLoader ());
52
+ private final ThrowawayClassLoader throwawayClassLoader = new ThrowawayClassLoader (getClass ().getClassLoader ());
53
+
52
54
53
55
@ Override
54
56
public void beforeAnalysis (BeforeAnalysisAccess access ) {
55
57
access .registerSubtypeReachabilityHandler (this ::iterateFields , Object .class );
56
58
}
57
59
58
- /* This method is invoked for every type that is reachable. */
60
+ // This method is invoked for every type that is reachable.
59
61
private void iterateFields (DuringAnalysisAccess access , Class <?> subtype ) {
60
62
try {
61
63
for (Field field : subtype .getDeclaredFields ()) {
@@ -71,12 +73,14 @@ private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
71
73
Object fieldValue = provideFieldValue (field );
72
74
access .registerFieldValueTransformer (field , (receiver , originalValue ) -> fieldValue );
73
75
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" );
75
78
}
76
79
}
77
80
catch (Throwable ex ) {
78
81
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 );
80
84
}
81
85
}
82
86
}
@@ -88,8 +92,10 @@ private void iterateFields(DuringAnalysisAccess access, Class<?> subtype) {
88
92
}
89
93
}
90
94
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
+
93
99
Class <?> throwawayClass = this .throwawayClassLoader .loadClass (field .getDeclaringClass ().getName ());
94
100
Field throwawayField = throwawayClass .getDeclaredField (field .getName ());
95
101
throwawayField .setAccessible (true );
0 commit comments