@@ -23,7 +23,7 @@ public abstract class PropertyFieldManager {
2323 private static final List <PropertyField > fields = new ArrayList <>();
2424
2525 /**
26- * The lock used to synchronize the access to the fields list.
26+ * The lock used to synchronize the access to the field list.
2727 */
2828 private static final ReentrantLock lock = new ReentrantLock ();
2929
@@ -60,8 +60,11 @@ private PropertyFieldManager() {
6060 */
6161 public static void addPropertyField (@ NotNull final PropertyField field ) {
6262 lock .lock ();
63- fields .add (field );
64- lock .unlock ();
63+ try {
64+ fields .add (field );
65+ } finally {
66+ lock .unlock ();
67+ }
6568 }
6669
6770 /**
@@ -78,27 +81,30 @@ public static boolean parseField(@NotNull final Object bean,
7881 @ NotNull final Field field ,
7982 @ NotNull final String value ) throws IllegalAccessException {
8083 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+ }
98103 }
99104 }
105+ } finally {
106+ lock .unlock ();
100107 }
101- lock .unlock ();
102108 log .warn ("Unsupported field type {} for field {}" ,
103109 field .getType ().getName (), field .getName ());
104110 return (false );
@@ -150,9 +156,13 @@ private static boolean parsePrimitiveField(@NotNull final Object bean,
150156 public static @ NotNull List <Class <?>> getImplementedClassList () {
151157 List <Class <?>> classes = new ArrayList <>();
152158 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+ }
156166 return (classes );
157167 }
158168
0 commit comments