1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.beanutils2.bugs;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 import java.util.ArrayList;
22 import java.util.List;
23 import java.util.concurrent.ExecutorService;
24 import java.util.concurrent.Executors;
25 import java.util.concurrent.Future;
26
27 import org.apache.commons.beanutils2.FluentPropertyBeanIntrospector;
28 import org.apache.commons.beanutils2.PropertyUtilsBean;
29 import org.junit.jupiter.api.Test;
30
31
32
33
34
35
36 public class Jira541Test {
37
38 public static class BaseType {
39
40 private String field;
41
42 public String getField() {
43 return field;
44 }
45
46 public BaseType setField(final String objectName) {
47 this.field = objectName;
48 return this;
49 }
50 }
51
52 public static class SubTypeA extends BaseType {
53
54 @Override
55 public SubTypeA setField(final String field) {
56 super.setField(field);
57 return this;
58 }
59 }
60
61 public static class SubTypeB extends BaseType {
62
63 }
64
65 private static final String FIELD_NAME = "field";
66
67 private static final String FIELD_VALUE = "name";
68
69 private static void testImpl() throws ReflectiveOperationException {
70 final PropertyUtilsBean propertyUtilsBean = new PropertyUtilsBean();
71 propertyUtilsBean.addBeanIntrospector(new FluentPropertyBeanIntrospector());
72
73
74
75 final SubTypeA subTypeA = new SubTypeA();
76 propertyUtilsBean.setProperty(subTypeA, FIELD_NAME, FIELD_VALUE);
77
78 final SubTypeB subTypeB = new SubTypeB();
79 propertyUtilsBean.setProperty(subTypeB, FIELD_NAME, FIELD_VALUE);
80
81 assertEquals(FIELD_VALUE, subTypeA.getField());
82 assertEquals(FIELD_VALUE, subTypeB.getField());
83 }
84
85 @Test
86 public void testFluentBeanIntrospectorOnOverriddenSetter() throws Exception {
87 testImpl();
88 }
89
90 @Test
91 public void testFluentBeanIntrospectorOnOverriddenSetterConcurrent() throws Exception {
92 final ExecutorService executionService = Executors.newFixedThreadPool(256);
93 try {
94 final List<Future<?>> futures = new ArrayList<>();
95 for (int i = 0; i < 10000; i++) {
96 futures.add(executionService.submit(() -> {
97 testImpl();
98 return null;
99 }));
100 }
101 for (final Future<?> future : futures) {
102 future.get();
103 }
104 } finally {
105 executionService.shutdown();
106 }
107 }
108 }