Skip to content
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
Expand Up @@ -233,7 +233,7 @@ private class CreateJmxConnector implements Callable<@Nullable JMXConnector> {
}

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

}
Expand Down
12 changes: 12 additions & 0 deletions config/checkstyle/checkstyle.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,18 @@
value="Please use static AssertJ imports." />
<property name="ignoreComments" value="true" />
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="maximum" value="0"/>
<property name="format" value="\.isAssignableFrom\(.+\.getClass\(\)\)" />
<property name="message" value="Please use type.isInstance(object) instead." />
<property name="ignoreComments" value="true" />
</module>
<module name="com.puppycrawl.tools.checkstyle.checks.regexp.RegexpSinglelineJavaCheck">
<property name="maximum" value="0"/>
<property name="format" value="\w+\.class\.isInstance\(.+\)" />
<property name="message" value="Please use object instanceof type instead." />
<property name="ignoreComments" value="true" />
</module>
<module name="io.spring.javaformat.checkstyle.check.SpringJavadocCheck">
<property name="publicOnlySinceTags" value="true" />
<property name="requireSinceTag" value="true" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ String getKind() throws Exception {
}

Object getLiteralValue() throws Exception {
if (this.literalTreeType.isAssignableFrom(getInstance().getClass())) {
if (this.literalTreeType.isInstance(getInstance())) {
return this.literalValueMethod.invoke(getInstance());
}
return null;
}

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

Member getSelectedMember() throws Exception {
if (this.memberSelectTreeType.isAssignableFrom(getInstance().getClass())) {
if (this.memberSelectTreeType.isInstance(getInstance())) {
String expression = this.memberSelectTreeExpressionMethod.invoke(getInstance()).toString();
String identifier = this.memberSelectTreeIdentifierMethod.invoke(getInstance()).toString();
if (expression != null && identifier != null) {
Expand All @@ -83,7 +83,7 @@ Member getSelectedMember() throws Exception {
}

List<? extends ExpressionTree> getArrayExpression() throws Exception {
if (this.newArrayTreeType.isAssignableFrom(getInstance().getClass())) {
if (this.newArrayTreeType.isInstance(getInstance())) {
List<?> elements = (List<?>) this.arrayValueMethod.invoke(getInstance());
List<ExpressionTree> result = new ArrayList<>();
if (elements == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public abstract class AbstractInjectionFailureAnalyzer<T extends Throwable> exte
Throwable candidate = root;
C result = null;
while (candidate != null) {
if (type.isAssignableFrom(candidate.getClass())) {
if (type.isInstance(candidate)) {
result = (C) candidate;
}
candidate = candidate.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ protected final <T> T tryParse(Callable<T> parser, Class<? extends Exception> ch
return parser.call();
}
catch (Exception ex) {
if (check.isAssignableFrom(ex.getClass())) {
if (check.isInstance(ex)) {
throw new JsonParseException(ex);
}
ReflectionUtils.rethrowRuntimeException(ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ else if (item instanceof List) {
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass()) || value instanceof String) {
return value;
}
if (CharSequence.class.isAssignableFrom(value.getClass())) {
if (value instanceof CharSequence) {
return value.toString();
}
return "Complex property value " + value.getClass().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,10 @@ private void extract(String root, Map<String, PropertySource<?>> map, PropertySo
}

protected @Nullable Object stringifyIfNecessary(@Nullable Object value) {
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass())
|| Number.class.isAssignableFrom(value.getClass())) {
if (value == null || ClassUtils.isPrimitiveOrWrapper(value.getClass()) || value instanceof Number) {
return value;
}
if (CharSequence.class.isAssignableFrom(value.getClass())) {
if (value instanceof CharSequence) {
return value.toString();
}
return "Complex property type " + value.getClass().getName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ private <T> T findEncoder(AssertableApplicationContext context, Class<T> encoder
.filter((writer) -> writer instanceof EncoderHttpMessageWriter<?>)
.map((writer) -> (EncoderHttpMessageWriter<?>) writer)
.map(EncoderHttpMessageWriter::getEncoder)
.filter((encoder) -> encoderClass.isAssignableFrom(encoder.getClass()))
.filter(encoderClass::isInstance)
.findFirst()
.orElseThrow();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -465,18 +465,14 @@ private ApplicationContextRunner allOptionsRunner() {

private void assertConverterIsRegistered(AssertableApplicationContext context,
Class<? extends HttpMessageConverter<?>> converterType) {
assertThat(getClientConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
.hasSize(1);
assertThat(getServerConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
.hasSize(1);
assertThat(getClientConverters(context)).filteredOn(converterType::isInstance).hasSize(1);
assertThat(getServerConverters(context)).filteredOn(converterType::isInstance).hasSize(1);
}

private void assertConverterIsNotRegistered(AssertableApplicationContext context,
Class<? extends HttpMessageConverter<?>> converterType) {
assertThat(getClientConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
.isEmpty();
assertThat(getServerConverters(context)).filteredOn((c) -> converterType.isAssignableFrom(c.getClass()))
.isEmpty();
assertThat(getClientConverters(context)).filteredOn(converterType::isInstance).isEmpty();
assertThat(getServerConverters(context)).filteredOn(converterType::isInstance).isEmpty();
}

private void assertBeanExists(AssertableApplicationContext context, Class<?> type, String beanName) {
Expand Down Expand Up @@ -504,7 +500,7 @@ private HttpMessageConverters getServerConverters(ApplicationContext context) {
private <T extends HttpMessageConverter<?>> T findConverter(HttpMessageConverters converters,
Class<? extends HttpMessageConverter<?>> type) {
for (HttpMessageConverter<?> converter : converters) {
if (type.isAssignableFrom(converter.getClass())) {
if (type.isInstance(converter)) {
return (T) converter;
}
}
Expand Down Expand Up @@ -589,8 +585,7 @@ static class JacksonConverterConfig {

@Bean
JacksonJsonHttpMessageConverter customJacksonMessageConverter(JsonMapper jsonMapperMapper) {
JacksonJsonHttpMessageConverter converter = new JacksonJsonHttpMessageConverter(jsonMapperMapper);
return converter;
return new JacksonJsonHttpMessageConverter(jsonMapperMapper);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ abstract class JdbcConnectionDetailsBeanPostProcessor<T> implements BeanPostProc
@Override
@SuppressWarnings("unchecked")
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
if (this.dataSourceClass.isAssignableFrom(bean.getClass()) && "dataSource".equals(beanName)) {
if (this.dataSourceClass.isInstance(bean) && "dataSource".equals(beanName)) {
JdbcConnectionDetails connectionDetails = this.connectionDetailsProvider.getObject();
if (!(connectionDetails instanceof PropertiesJdbcConnectionDetails)) {
return processDataSource((T) bean, connectionDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class TracingAndMeterObservationHandlerGroup implements ObservationHandlerGroup

@Override
public boolean isMember(ObservationHandler<?> handler) {
return MeterObservationHandler.class.isInstance(handler) || TracingObservationHandler.class.isInstance(handler);
return handler instanceof MeterObservationHandler || handler instanceof TracingObservationHandler;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ private <T extends ProtocolHandler> void customizeHandler(ConfigurableTomcatWebS
Class<T> type, ObjIntConsumer<T> consumer) {
factory.addConnectorCustomizers((connector) -> {
ProtocolHandler handler = connector.getProtocolHandler();
if (type.isAssignableFrom(handler.getClass())) {
if (type.isInstance(handler)) {
consumer.accept(type.cast(handler), value);
}
});
Expand Down
Loading