Skip to content

Commit 7a45ee8

Browse files
committed
Merge branch '4.0.x'
Closes gh-50851
2 parents 73010ce + 790f66c commit 7a45ee8

12 files changed

Lines changed: 32 additions & 26 deletions

File tree

build-plugin/spring-boot-maven-plugin/src/main/java/org/springframework/boot/maven/StartMojo.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ private class CreateJmxConnector implements Callable<@Nullable JMXConnector> {
233233
}
234234

235235
private boolean hasCauseWithType(Throwable t, Class<? extends Exception> type) {
236-
return type.isAssignableFrom(t.getClass()) || t.getCause() != null && hasCauseWithType(t.getCause(), type);
236+
return type.isInstance(t) || t.getCause() != null && hasCauseWithType(t.getCause(), type);
237237
}
238238

239239
}

config/checkstyle/checkstyle.xml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,18 @@
8888
value="Please use static AssertJ imports." />
8989
<property name="ignoreComments" value="true" />
9090
</module>
91+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
92+
<property name="maximum" value="0"/>
93+
<property name="format" value="\.isAssignableFrom\(.+\.getClass\(\)\)" />
94+
<property name="message" value="Please use type.isInstance(object) instead." />
95+
<property name="ignoreComments" value="true" />
96+
</module>
97+
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
98+
<property name="maximum" value="0"/>
99+
<property name="format" value="\w+\.class\.isInstance\(.+\)" />
100+
<property name="message" value="Please use object instanceof type instead." />
101+
<property name="ignoreComments" value="true" />
102+
</module>
91103
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck">
92104
<property name="publicOnlySinceTags" value="true" />
93105
<property name="requireSinceTag" value="true" />

configuration-metadata/spring-boot-configuration-processor/src/main/java/org/springframework/boot/configurationprocessor/fieldvalues/javac/ExpressionTree.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,14 @@ String getKind() throws Exception {
5555
}
5656

5757
Object getLiteralValue() throws Exception {
58-
if (this.literalTreeType.isAssignableFrom(getInstance().getClass())) {
58+
if (this.literalTreeType.isInstance(getInstance())) {
5959
return this.literalValueMethod.invoke(getInstance());
6060
}
6161
return null;
6262
}
6363

6464
Object getFactoryValue() throws Exception {
65-
if (this.methodInvocationTreeType.isAssignableFrom(getInstance().getClass())) {
65+
if (this.methodInvocationTreeType.isInstance(getInstance())) {
6666
List<?> arguments = (List<?>) this.methodInvocationArgumentsMethod.invoke(getInstance());
6767
if (arguments.size() == 1) {
6868
return new ExpressionTree(arguments.get(0)).getLiteralValue();
@@ -72,7 +72,7 @@ Object getFactoryValue() throws Exception {
7272
}
7373

7474
Member getSelectedMember() throws Exception {
75-
if (this.memberSelectTreeType.isAssignableFrom(getInstance().getClass())) {
75+
if (this.memberSelectTreeType.isInstance(getInstance())) {
7676
String expression = this.memberSelectTreeExpressionMethod.invoke(getInstance()).toString();
7777
String identifier = this.memberSelectTreeIdentifierMethod.invoke(getInstance()).toString();
7878
if (expression != null && identifier != null) {
@@ -83,7 +83,7 @@ Member getSelectedMember() throws Exception {
8383
}
8484

8585
List<? extends ExpressionTree> getArrayExpression() throws Exception {
86-
if (this.newArrayTreeType.isAssignableFrom(getInstance().getClass())) {
86+
if (this.newArrayTreeType.isInstance(getInstance())) {
8787
List<?> elements = (List<?>) this.arrayValueMethod.invoke(getInstance());
8888
List<ExpressionTree> result = new ArrayList<>();
8989
if (elements == null) {

core/spring-boot/src/main/java/org/springframework/boot/diagnostics/analyzer/AbstractInjectionFailureAnalyzer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public abstract class AbstractInjectionFailureAnalyzer<T extends Throwable> exte
6464
Throwable candidate = root;
6565
C result = null;
6666
while (candidate != null) {
67-
if (type.isAssignableFrom(candidate.getClass())) {
67+
if (type.isInstance(candidate)) {
6868
result = (C) candidate;
6969
}
7070
candidate = candidate.getCause();

core/spring-boot/src/main/java/org/springframework/boot/json/AbstractJsonParser.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ protected final <T> T tryParse(Callable<T> parser, Class<? extends Exception> ch
5555
return parser.call();
5656
}
5757
catch (Exception ex) {
58-
if (check.isAssignableFrom(ex.getClass())) {
58+
if (check.isInstance(ex)) {
5959
throw new JsonParseException(ex);
6060
}
6161
ReflectionUtils.rethrowRuntimeException(ex);

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/context/properties/ConfigurationPropertiesReportEndpoint.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ else if (item instanceof List) {
337337
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass()) || value instanceof String) {
338338
return value;
339339
}
340-
if (CharSequence.class.isAssignableFrom(value.getClass())) {
340+
if (value instanceof CharSequence) {
341341
return value.toString();
342342
}
343343
return "Complex property value " + value.getClass().getName();

module/spring-boot-actuator/src/main/java/org/springframework/boot/actuate/env/EnvironmentEndpoint.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,10 @@ private void extract(String root, Map<String, PropertySource<?>> map, PropertySo
208208
}
209209

210210
protected @Nullable Object stringifyIfNecessary(@Nullable Object value) {
211-
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass())
212-
|| Number.class.isAssignableFrom(value.getClass())) {
211+
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass()) || value instanceof Number) {
213212
return value;
214213
}
215-
if (CharSequence.class.isAssignableFrom(value.getClass())) {
214+
if (value instanceof CharSequence) {
216215
return value.toString();
217216
}
218217
return "Complex property type " + value.getClass().getName();

module/spring-boot-http-codec/src/test/java/org/springframework/boot/http/codec/autoconfigure/CodecsAutoConfigurationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ private <T> T findEncoder(AssertableApplicationContext context, Class<T> encoder
169169
.filter((writer) -> writer instanceof EncoderHttpMessageWriter<?>)
170170
.map((writer) -> (EncoderHttpMessageWriter<?>) writer)
171171
.map(EncoderHttpMessageWriter::getEncoder)
172-
.filter((encoder) -> encoderClass.isAssignableFrom(encoder.getClass()))
172+
.filter(encoderClass::isInstance)
173173
.findFirst()
174174
.orElseThrow();
175175
}

module/spring-boot-http-converter/src/test/java/org/springframework/boot/http/converter/autoconfigure/HttpMessageConvertersAutoConfigurationTests.java

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -465,18 +465,14 @@ private ApplicationContextRunner allOptionsRunner() {
465465

466466
private void assertConverterIsRegistered(AssertableApplicationContext context,
467467
Class<? extends HttpMessageConverter<?>> converterType) {
468-
assertThat(getClientConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
469-
.hasSize(1);
470-
assertThat(getServerConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
471-
.hasSize(1);
468+
assertThat(getClientConverters(context)).filteredOn(converterType::isInstance).hasSize(1);
469+
assertThat(getServerConverters(context)).filteredOn(converterType::isInstance).hasSize(1);
472470
}
473471

474472
private void assertConverterIsNotRegistered(AssertableApplicationContext context,
475473
Class<? extends HttpMessageConverter<?>> converterType) {
476-
assertThat(getClientConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
477-
.isEmpty();
478-
assertThat(getServerConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
479-
.isEmpty();
474+
assertThat(getClientConverters(context)).filteredOn(converterType::isInstance).isEmpty();
475+
assertThat(getServerConverters(context)).filteredOn(converterType::isInstance).isEmpty();
480476
}
481477

482478
private void assertBeanExists(AssertableApplicationContext context, Class<?> type, String beanName) {
@@ -504,7 +500,7 @@ private HttpMessageConverters getServerConverters(ApplicationContext context) {
504500
private <T extends HttpMessageConverter<?>> T findConverter(HttpMessageConverters converters,
505501
Class<? extends HttpMessageConverter<?>> type) {
506502
for (HttpMessageConverter<?> converter : converters) {
507-
if (type.isAssignableFrom(converter.getClass())) {
503+
if (type.isInstance(converter)) {
508504
return (T) converter;
509505
}
510506
}
@@ -589,8 +585,7 @@ static class JacksonConverterConfig {
589585

590586
@Bean
591587
JacksonJsonHttpMessageConverter customJacksonMessageConverter(JsonMapper jsonMapperMapper) {
592-
JacksonJsonHttpMessageConverter converter = new JacksonJsonHttpMessageConverter(jsonMapperMapper);
593-
return converter;
588+
return new JacksonJsonHttpMessageConverter(jsonMapperMapper);
594589
}
595590

596591
}

module/spring-boot-jdbc/src/main/java/org/springframework/boot/jdbc/autoconfigure/JdbcConnectionDetailsBeanPostProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ abstract class JdbcConnectionDetailsBeanPostProcessor<T> implements BeanPostProc
4949
@Override
5050
@SuppressWarnings("unchecked")
5151
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
52-
if (this.dataSourceClass.isAssignableFrom(bean.getClass()) && "dataSource".equals(beanName)) {
52+
if (this.dataSourceClass.isInstance(bean) && "dataSource".equals(beanName)) {
5353
JdbcConnectionDetails connectionDetails = this.connectionDetailsProvider.getObject();
5454
if (!(connectionDetails instanceof PropertiesJdbcConnectionDetails)) {
5555
return processDataSource((T) bean, connectionDetails);

0 commit comments

Comments
 (0)