Skip to content

Commit 5d52967

Browse files
Migrate legacy reflection properties to use MethodHandles
Fixes #2083
1 parent d4a4cf0 commit 5d52967

File tree

10 files changed

+304
-371
lines changed

10 files changed

+304
-371
lines changed

Diff for: src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java

+14-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
package tools.jackson.databind.deser;
22

3+
import java.lang.invoke.MethodHandles;
4+
import java.lang.reflect.Field;
5+
import java.lang.reflect.Modifier;
36
import java.util.*;
47

58
import com.fasterxml.jackson.annotation.*;
@@ -935,14 +938,13 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
935938
// Does the Method specify the deserializer to use? If so, let's use it.
936939
TypeDeserializer typeDeser = (TypeDeserializer) type.getTypeHandler();
937940
SettableBeanProperty prop;
938-
if (mutator instanceof AnnotatedMethod) {
939-
prop = new MethodProperty(propDef, type, typeDeser,
940-
beanDesc.getClassAnnotations(), (AnnotatedMethod) mutator);
941-
} else {
942-
// 08-Sep-2016, tatu: wonder if we should verify it is `AnnotatedField` to be safe?
943-
prop = new FieldProperty(propDef, type, typeDeser,
944-
beanDesc.getClassAnnotations(), (AnnotatedField) mutator);
941+
if (!ClassUtil.checkAndFixAccess(mutator.getMember(), ctxt.getConfig().isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS))) {
942+
return null;
945943
}
944+
if (finalField(mutator)) {
945+
return null;
946+
}
947+
prop = new MethodProperty(propDef, type, typeDeser, beanDesc.getClassAnnotations(), mutator);
946948
ValueDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, mutator);
947949
if (deser == null) {
948950
deser = (ValueDeserializer<?>) type.getValueHandler();
@@ -963,6 +965,11 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
963965
return prop;
964966
}
965967

968+
private boolean finalField(AnnotatedMember am) {
969+
return am instanceof AnnotatedField
970+
&& Modifier.isFinal(am.getMember().getModifiers());
971+
}
972+
966973
/**
967974
* Method that will construct a regular bean property setter using
968975
* the given setter method.

Diff for: src/main/java/tools/jackson/databind/deser/SettableBeanProperty.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -609,7 +609,7 @@ public SettableBeanProperty unwrapped(DeserializationContext ctxt, NameTransform
609609
/**********************************************************************
610610
*/
611611

612-
protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
612+
protected void _throwAsJacksonE(JsonParser p, Throwable e, Object value)
613613
throws JacksonException
614614
{
615615
if (e instanceof IllegalArgumentException) {
@@ -632,8 +632,9 @@ protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
632632
_throwAsJacksonE(p, e);
633633
}
634634

635-
protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonException
635+
protected void _throwAsJacksonE(JsonParser p, Throwable e) throws JacksonException
636636
{
637+
ClassUtil.throwIfError(e);
637638
ClassUtil.throwIfRTE(e);
638639
ClassUtil.throwIfJacksonE(e);
639640
// let's wrap the innermost problem
@@ -643,7 +644,7 @@ protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonExcepti
643644

644645
// 10-Oct-2015, tatu: _Should_ be deprecated, too, but its remaining
645646
// callers cannot actually provide a JsonParser
646-
protected void _throwAsJacksonE(Exception e, Object value) throws JacksonException {
647+
protected void _throwAsJacksonE(Throwable e, Object value) throws JacksonException {
647648
_throwAsJacksonE((JsonParser) null, e, value);
648649
}
649650

Diff for: src/main/java/tools/jackson/databind/deser/impl/FieldProperty.java

-227
This file was deleted.

0 commit comments

Comments
 (0)