Skip to content

Commit 9659bc5

Browse files
committed
ObjectToObjectConverter properly handles constructors on non-public classes
Issue: SPR-14304
1 parent ac80ac6 commit 9659bc5

File tree

3 files changed

+9
-11
lines changed

3 files changed

+9
-11
lines changed

spring-core/src/main/java/org/springframework/core/convert/support/ObjectToObjectConverter.java

+1
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ public Object convert(Object source, TypeDescriptor sourceType, TypeDescriptor t
102102
}
103103
else if (member instanceof Constructor) {
104104
Constructor<?> ctor = (Constructor<?>) member;
105+
ReflectionUtils.makeAccessible(ctor);
105106
return ctor.newInstance(source);
106107
}
107108
}

spring-core/src/test/java/org/springframework/core/convert/support/DefaultConversionServiceTests.java renamed to spring-core/src/test/java/org/springframework/core/convert/converter/DefaultConversionServiceTests.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.core.convert.support;
17+
package org.springframework.core.convert.converter;
1818

1919
import java.awt.Color;
2020
import java.lang.reflect.Method;
@@ -50,8 +50,7 @@
5050
import org.springframework.core.convert.ConversionFailedException;
5151
import org.springframework.core.convert.ConverterNotFoundException;
5252
import org.springframework.core.convert.TypeDescriptor;
53-
import org.springframework.core.convert.converter.Converter;
54-
import org.springframework.core.convert.converter.ConverterRegistry;
53+
import org.springframework.core.convert.support.DefaultConversionService;
5554
import org.springframework.tests.Assume;
5655
import org.springframework.tests.TestGroup;
5756
import org.springframework.util.ClassUtils;
@@ -61,16 +60,16 @@
6160
import static org.junit.Assert.*;
6261

6362
/**
64-
* Unit tests for the {@link DefaultConversionService}.
63+
* Unit tests for {@link DefaultConversionService}.
6564
*
66-
* <p>For tests involving the {@link GenericConversionService}, see
67-
* {@link GenericConversionServiceTests}.
65+
* <p>In this package for enforcing accessibility checks to non-public classes outside
66+
* of the {@code org.springframework.core.convert.support} implementation package.
67+
* Only in such a scenario, {@code setAccessible(true)} is actually necessary.
6868
*
6969
* @author Keith Donald
7070
* @author Juergen Hoeller
7171
* @author Stephane Nicoll
7272
* @author Sam Brannen
73-
* @see GenericConversionServiceTests
7473
*/
7574
public class DefaultConversionServiceTests {
7675

spring-core/src/test/java/org/springframework/core/convert/support/GenericConversionServiceTests.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,15 @@
5454
import static org.junit.Assert.*;
5555

5656
/**
57-
* Unit tests for the {@link GenericConversionService}.
57+
* Unit tests for {@link GenericConversionService}.
5858
*
59-
* <p>For tests involving the {@link DefaultConversionService}, see
60-
* {@link DefaultConversionServiceTests}.
59+
* <p>In this package for access to package-local converter implementations.
6160
*
6261
* @author Keith Donald
6362
* @author Juergen Hoeller
6463
* @author Phillip Webb
6564
* @author David Haraburda
6665
* @author Sam Brannen
67-
* @see DefaultConversionServiceTests
6866
*/
6967
public class GenericConversionServiceTests {
7068

0 commit comments

Comments
 (0)