Skip to content

Replace core reflection usage with MethodHandles #5046

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.jackson.databind.deser;

import java.lang.reflect.Modifier;
import java.util.*;

import com.fasterxml.jackson.annotation.*;
Expand Down Expand Up @@ -935,14 +936,15 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
// Does the Method specify the deserializer to use? If so, let's use it.
TypeDeserializer typeDeser = (TypeDeserializer) type.getTypeHandler();
SettableBeanProperty prop;
if (mutator instanceof AnnotatedMethod) {
prop = new MethodProperty(propDef, type, typeDeser,
beanDesc.getClassAnnotations(), (AnnotatedMethod) mutator);
} else {
// 08-Sep-2016, tatu: wonder if we should verify it is `AnnotatedField` to be safe?
prop = new FieldProperty(propDef, type, typeDeser,
beanDesc.getClassAnnotations(), (AnnotatedField) mutator);
// 06-04-2025, scs: we cannot always see members if e.g. they are in a different module that does not
// allow our access, so filter such cases out here.
if (!ClassUtil.checkAndFixAccess(mutator.getMember(), ctxt.isEnabled(MapperFeature.OVERRIDE_PUBLIC_ACCESS_MODIFIERS))) {
return null;
}
if (isFinalField(mutator)) {
return null;
}
prop = new MethodProperty(propDef, type, typeDeser, beanDesc.getClassAnnotations(), mutator);
ValueDeserializer<?> deser = findDeserializerFromAnnotation(ctxt, mutator);
if (deser == null) {
deser = (ValueDeserializer<?>) type.getValueHandler();
Expand All @@ -963,6 +965,11 @@ protected SettableBeanProperty constructSettableProperty(DeserializationContext
return prop;
}

private boolean isFinalField(AnnotatedMember am) {
return am instanceof AnnotatedField
&& Modifier.isFinal(am.getMember().getModifiers());
}

/**
* Method that will construct a regular bean property setter using
* the given setter method.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ public SettableBeanProperty unwrapped(DeserializationContext ctxt, NameTransform
/**********************************************************************
*/

protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
protected void _throwAsJacksonE(JsonParser p, Throwable e, Object value)
throws JacksonException
{
if (e instanceof IllegalArgumentException) {
Expand All @@ -632,8 +632,9 @@ protected void _throwAsJacksonE(JsonParser p, Exception e, Object value)
_throwAsJacksonE(p, e);
}

protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonException
protected void _throwAsJacksonE(JsonParser p, Throwable e) throws JacksonException
{
ClassUtil.throwIfError(e);
ClassUtil.throwIfRTE(e);
ClassUtil.throwIfJacksonE(e);
// let's wrap the innermost problem
Expand All @@ -643,7 +644,7 @@ protected void _throwAsJacksonE(JsonParser p, Exception e) throws JacksonExcepti

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

Expand Down
227 changes: 0 additions & 227 deletions src/main/java/tools/jackson/databind/deser/impl/FieldProperty.java

This file was deleted.

Loading