@@ -23,7 +23,7 @@ public abstract class PropertyFieldManager {
23
23
private static final List <PropertyField > fields = new ArrayList <>();
24
24
25
25
/**
26
- * The lock used to synchronize the access to the fields list.
26
+ * The lock used to synchronize the access to the field list.
27
27
*/
28
28
private static final ReentrantLock lock = new ReentrantLock ();
29
29
@@ -60,8 +60,11 @@ private PropertyFieldManager() {
60
60
*/
61
61
public static void addPropertyField (@ NotNull final PropertyField field ) {
62
62
lock .lock ();
63
- fields .add (field );
64
- lock .unlock ();
63
+ try {
64
+ fields .add (field );
65
+ } finally {
66
+ lock .unlock ();
67
+ }
65
68
}
66
69
67
70
/**
@@ -78,27 +81,30 @@ public static boolean parseField(@NotNull final Object bean,
78
81
@ NotNull final Field field ,
79
82
@ NotNull final String value ) throws IllegalAccessException {
80
83
lock .lock ();
81
- // Verify if the field is final.
82
- if ((field .getModifiers () & Modifier .FINAL ) == Modifier .FINAL ) {
83
- log .warn ("Field {} is final, skipping updating" , field .getName ());
84
- return (false );
85
- }
86
- // Verify if the field is primitive.
87
- if (parsePrimitiveField (bean , field , value ))
88
- return (true );
89
- for (PropertyField propertyField : fields ) {
90
- if (propertyField .getType () == field .getType ()) {
91
- try {
92
- field .setAccessible (true );
93
- field .set (bean , propertyField .parseString (value ));
94
- return (true );
95
- } catch (IllegalAccessException e ) {
96
- log .error ("Unable to set field {} to value {}" , field .getName (), value , e );
97
- return (false );
84
+ try {
85
+ // Verify if the field is final.
86
+ if ((field .getModifiers () & Modifier .FINAL ) == Modifier .FINAL ) {
87
+ log .warn ("Field {} is final, skipping updating" , field .getName ());
88
+ return (false );
89
+ }
90
+ // Verify if the field is primitive.
91
+ if (parsePrimitiveField (bean , field , value ))
92
+ return (true );
93
+ for (PropertyField propertyField : fields ) {
94
+ if (propertyField .getType () == field .getType ()) {
95
+ try {
96
+ field .setAccessible (true );
97
+ field .set (bean , propertyField .parseString (value ));
98
+ return (true );
99
+ } catch (IllegalAccessException e ) {
100
+ log .error ("Unable to set field {} to value {}" , field .getName (), value , e );
101
+ return (false );
102
+ }
98
103
}
99
104
}
105
+ } finally {
106
+ lock .unlock ();
100
107
}
101
- lock .unlock ();
102
108
log .warn ("Unsupported field type {} for field {}" ,
103
109
field .getType ().getName (), field .getName ());
104
110
return (false );
@@ -150,9 +156,13 @@ private static boolean parsePrimitiveField(@NotNull final Object bean,
150
156
public static @ NotNull List <Class <?>> getImplementedClassList () {
151
157
List <Class <?>> classes = new ArrayList <>();
152
158
lock .lock ();
153
- for (PropertyField field : fields )
154
- classes .add (field .getType ());
155
- lock .unlock ();
159
+ try {
160
+ for (PropertyField field : fields ) {
161
+ classes .add (field .getType ());
162
+ }
163
+ } finally {
164
+ lock .unlock ();
165
+ }
156
166
return (classes );
157
167
}
158
168
0 commit comments