Skip to content

Commit 3e2d96b

Browse files
Migrate legacy reflection properties to use MethodHandles
Fixes #2083
1 parent 391af95 commit 3e2d96b

File tree

10 files changed

+310
-374
lines changed

10 files changed

+310
-374
lines changed

src/main/java/tools/jackson/databind/deser/BeanDeserializerFactory.java

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

3+
import java.lang.reflect.Modifier;
34
import java.util.*;
45

56
import com.fasterxml.jackson.annotation.*;
@@ -935,14 +936,15 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
935936
// Does the Method specify the deserializer to use? If so, let's use it.
936937
TypeDeserializer typeDeser = (TypeDeserializer) type.getTypeHandler();
937938
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);
939+
// 06-04-2025, scs: we cannot always see members if e.g. they are in a different module that does not
940+
// allow our access, so filter such cases out here.
941+
if (!ClassUtil.checkAndFixAccess(mutator.getMember(), ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS))) {
942+
return null;
945943
}
944+
if (isFinalField(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 isFinalField(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.

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

src/main/java/tools/jackson/databind/deser/impl/FieldProperty.java

-227
This file was deleted.

0 commit comments

Comments
 (0)