Skip to content

Commit e7274f7

Browse files
authored
Fix #6229: @ConstructorProperties must not be gated by DETECT_PARAMETER_NAMES (#6230)
1 parent 1da96dd commit e7274f7

7 files changed

Lines changed: 52 additions & 9 deletions

File tree

‎release-notes/CREDITS‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -746,3 +746,8 @@ Sergey Lappo (@sergeylappo)
746746
* Reported #6227: `BeanDescription` is not thread-safe when called concurrently on the
747747
same instance (`findProperties()`, `findDefaultViews()`)
748748
[3.2.4]
749+
750+
Mauricio Souza (@mauriciocsz)
751+
* Reported, contributed fix for #6229: `DETECT_PARAMETER_NAMES` disabled also prevents
752+
`@ConstructorProperties` based Creator detection
753+
[3.3.0]

‎release-notes/VERSION‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ Versions: 3.x (for earlier see VERSION-2.x)
8080
(Default Typing, `@JsonTypeInfo`) resolves a type id: type deserializer was built
8181
for the declared type, before the refinement
8282
(fix by @pjfanning)
83+
#6229: `DETECT_PARAMETER_NAMES` disabled also prevents `@ConstructorProperties`
84+
based Creator detection
85+
(fix by @mauriciocsz)
8386
#6231: Add copy constructor for `JacksonAnnotationIntrospector` (for sub-classes
8487
to create re-configured copies)
8588
(fix by @cowtowncoder, w/ Claude code)

‎src/main/java/tools/jackson/databind/introspect/JacksonAnnotationIntrospector.java‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -366,11 +366,10 @@ public VisibilityChecker findAutoDetectVisibility(MapperConfig<?> config,
366366
@Override
367367
public String findImplicitPropertyName(MapperConfig<?> config, AnnotatedMember m)
368368
{
369-
// 15-Sep-2025: As per [databind#5314] possible to disable introspection
370-
if (!config.isEnabled(MapperFeature.DETECT_PARAMETER_NAMES)) {
371-
return null;
372-
}
373369
if (m instanceof AnnotatedParameter p) {
370+
// 15-Sep-2025: As per [databind#5314] possible to disable introspection
371+
final boolean detectParamNames = config.isEnabled(MapperFeature.DETECT_PARAMETER_NAMES);
372+
374373
AnnotatedWithParams owner = p.getOwner();
375374
if (owner instanceof AnnotatedConstructor) {
376375
// 15-Sep-2025, tatu: May seem odd but we'll keep access dynamic due
@@ -383,12 +382,15 @@ public String findImplicitPropertyName(MapperConfig<?> config, AnnotatedMember m
383382
}
384383
}
385384
// ... or parameter names from bytecode (JDK8)
386-
return _findImplicitName(owner, p.getIndex());
385+
if (detectParamNames) {
386+
return _findImplicitName(owner, p.getIndex());
387+
}
388+
return null;
387389
}
388390
if (owner instanceof AnnotatedMethod) {
389391
// For now let's only bother discovering names for static methods as they
390392
// (only) may be creators
391-
if (owner.isStatic()) {
393+
if (detectParamNames && owner.isStatic()) {
392394
return _findImplicitName(owner, p.getIndex());
393395
}
394396
}

‎src/test/java/tools/jackson/databind/deser/WithoutParamNamesModule5314Test.java‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package tools.jackson.databind.deser;
22

3+
import java.beans.ConstructorProperties;
4+
35
import org.junit.jupiter.api.Test;
46

57
import tools.jackson.databind.MapperFeature;
@@ -27,6 +29,21 @@ public Bean178(String openName, int openAge) {
2729
}
2830
}
2931

32+
// [databind#6229]: same shape as Bean178 above, but with `@ConstructorProperties`
33+
// added -- specifically to validate Jackson 2.x compatibility, `@ConstructorProperties`
34+
// must keep resolving names regardless of `DETECT_PARAMETER_NAMES`.
35+
static class CtorPropsBean6229
36+
{
37+
final String hiddenName;
38+
final int hiddenAge;
39+
40+
@ConstructorProperties({"openName", "openAge"})
41+
public CtorPropsBean6229(String openName, int openAge) {
42+
hiddenName = openName;
43+
hiddenAge = openAge;
44+
}
45+
}
46+
3047
private final String JSON = a2q("{'openName':'stu','openAge':22}");
3148

3249
@Test
@@ -46,10 +63,29 @@ public void testWorksByDefault()
4663
.builderWithJackson2Defaults().build());
4764
}
4865

66+
// [databind#6229]: `CtorPropsBean178` (see above) must deserialize
67+
// successfully under all three configs below.
68+
@Test
69+
public void testConstructorPropertiesIgnoresDetectParameterNames()
70+
{
71+
_runCtorPropsSuccess(JsonMapper.builder()
72+
.enable(MapperFeature.DETECT_PARAMETER_NAMES).build());
73+
_runCtorPropsSuccess(JsonMapper.builder()
74+
.disable(MapperFeature.DETECT_PARAMETER_NAMES).build());
75+
_runCtorPropsSuccess(JsonMapper
76+
.builderWithJackson2Defaults().build());
77+
}
78+
4979
private void _runTestSuccess(JsonMapper mapper)
5080
{
5181
Bean178 bean = mapper.readValue(JSON, Bean178.class);
82+
assertEquals("stu", bean.hiddenName);
83+
assertEquals(22, bean.hiddenAge);
84+
}
5285

86+
private void _runCtorPropsSuccess(JsonMapper mapper)
87+
{
88+
CtorPropsBean6229 bean = mapper.readValue(JSON, CtorPropsBean6229.class);
5389
assertEquals("stu", bean.hiddenName);
5490
assertEquals(22, bean.hiddenAge);
5591
}

‎src/test/java/tools/jackson/databind/deser/creators/TestCreators2.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11

22
package tools.jackson.databind.deser.creators;
33

4-
import java.io.IOException;
54
import java.util.List;
65
import java.util.Map;
76

‎src/test/java/tools/jackson/databind/deser/dos/DeepNestingUntypedDeserTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
import tools.jackson.databind.ObjectMapper;
1212
import tools.jackson.databind.json.JsonMapper;
1313

14-
import static org.junit.jupiter.api.Assertions.assertTrue;
1514
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
1615

1716
// For [databind#2816] / [databind#3473]

‎src/test/java/tools/jackson/databind/ext/jdk9/Java9ListsTest.java‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
import static org.junit.jupiter.api.Assertions.assertEquals;
1616
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
17-
import static org.junit.jupiter.api.Assertions.assertTrue;
1817

1918
// for [databind#2900]
2019
public class Java9ListsTest extends DatabindTestUtil

0 commit comments

Comments
 (0)