Skip to content

Commit 9826219

Browse files
committed
PgTypeHelper fixes.
1 parent a89773f commit 9826219

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

src/main/java/org/zalando/typemapper/postgres/PgTypeHelper.java

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import java.lang.reflect.Array;
44
import java.lang.reflect.Field;
5-
5+
import java.lang.reflect.InvocationTargetException;
66
import java.sql.Connection;
77
import java.sql.SQLException;
88
import java.sql.Timestamp;
@@ -265,9 +265,7 @@ public int compare(final Field a, final Field b) {
265265
for (final Field f : fields) {
266266
final DatabaseFieldDescriptor databaseFieldDescriptor = getDatabaseFieldDescriptor(f);
267267
if (databaseFieldDescriptor != null) {
268-
if (!f.isAccessible()) {
269-
f.setAccessible(true);
270-
}
268+
f.trySetAccessible();
271269

272270
Object value;
273271
try {
@@ -417,28 +415,44 @@ private static Object applyTransformer(final Field f, final DatabaseFieldDescrip
417415
try {
418416
@SuppressWarnings("unchecked")
419417
final ValueTransformer<Object, Object> transformer = (ValueTransformer<Object, Object>)
420-
databaseFieldDescriptor.getTransformer().newInstance();
418+
databaseFieldDescriptor.getTransformer().getDeclaredConstructor().newInstance();
421419

422420
// transform the value by the transformer into a database value:
423421
value = transformer.marshalToDb(value);
424422
} catch (final InstantiationException e) {
425423
throw new IllegalArgumentException("Could not instantiate transformer of field " + f.getName(), e);
426424
} catch (final IllegalAccessException e) {
427425
throw new IllegalArgumentException("Could not instantiate transformer of field " + f.getName(), e);
426+
} catch (final InvocationTargetException e) {
427+
throw new IllegalArgumentException("Could not instantiate transformer of field " + f.getName(), e);
428+
} catch (IllegalArgumentException e) {
429+
throw new IllegalArgumentException("Could not instantiate transformer of field " + f.getName(), e);
430+
} catch (NoSuchMethodException e) {
431+
throw new IllegalArgumentException("Could not instantiate transformer of field " + f.getName(), e);
432+
} catch (SecurityException e) {
433+
throw new IllegalArgumentException("Could not instantiate transformer of field " + f.getName(), e);
428434
}
429435
}
430436

431437
Class<? extends ObjectMapper<?>> mapperClass = databaseFieldDescriptor.getMapper();
432438
if (mapperClass != null && mapperClass != DefaultObjectMapper.class) {
433439
try {
434440
@SuppressWarnings("unchecked")
435-
ObjectMapper<Object> mapper = (ObjectMapper<Object>) mapperClass.newInstance();
441+
ObjectMapper<Object> mapper = (ObjectMapper<Object>) mapperClass.getDeclaredConstructor().newInstance();
436442

437443
value = mapper.marshalToDb(value);
438444
} catch (InstantiationException e) {
439445
throw new IllegalArgumentException("Could not instantiate mapper of field " + f.getName(), e);
440446
} catch (IllegalAccessException e) {
441447
throw new IllegalArgumentException("Could not instantiate mapper of field " + f.getName(), e);
448+
} catch (IllegalArgumentException e) {
449+
throw new IllegalArgumentException("Could not instantiate mapper of field " + f.getName(), e);
450+
} catch (InvocationTargetException e) {
451+
throw new IllegalArgumentException("Could not instantiate mapper of field " + f.getName(), e);
452+
} catch (NoSuchMethodException e) {
453+
throw new IllegalArgumentException("Could not instantiate mapper of field " + f.getName(), e);
454+
} catch (SecurityException e) {
455+
throw new IllegalArgumentException("Could not instantiate mapper of field " + f.getName(), e);
442456
}
443457
}
444458

0 commit comments

Comments
 (0)