Skip to content
Open
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 @@ -32,7 +32,7 @@ example writes notifications to the console:
}
public boolean isNotificationEnabled(Notification notification) {
return AttributeChangeNotification.class.isAssignableFrom(notification.getClass());
return notification instanceof AttributeChangeNotification;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return notification instanceof AttributeChangeNotification;
return (notification instanceof AttributeChangeNotification);

}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public void setThrowingName(String name) {
* is only invoked if the thrown exception is a subtype of the given throwing type.
*/
private boolean shouldInvokeOnThrowing(Throwable ex) {
return getDiscoveredThrowingType().isAssignableFrom(ex.getClass());
return getDiscoveredThrowingType().isInstance(ex);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public Object instantiate(RootBeanDefinition bd, @Nullable String beanName, Bean
return result;
}
catch (IllegalArgumentException ex) {
if (factoryBean != null && !factoryMethod.getDeclaringClass().isAssignableFrom(factoryBean.getClass())) {
if (factoryBean != null && !factoryMethod.getDeclaringClass().isInstance(factoryBean)) {
throw new BeanInstantiationException(factoryMethod,
"Illegal factory instance for factory method '" + factoryMethod.getName() + "'; " +
"instance: " + factoryBean.getClass().getName(), ex);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ private Object instantiateUserDefinedStrategy(
strategyType.getName() + "]: a zero-argument constructor is required", ex);
}

if (!strategyType.isAssignableFrom(result.getClass())) {
if (!strategyType.isInstance(result)) {
throw new IllegalArgumentException("Provided class name must be an implementation of " + strategyType);
}
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ private static Field[] getDeclaredFields(Class<?> clazz) {
public static void shallowCopyFieldState(final Object src, final Object dest) {
Assert.notNull(src, "Source for field copy cannot be null");
Assert.notNull(dest, "Destination for field copy cannot be null");
if (!src.getClass().isAssignableFrom(dest.getClass())) {
if (!src.getClass().isInstance(dest)) {
throw new IllegalArgumentException("Destination class [" + dest.getClass().getName() +
"] must be same or subclass as source class [" + src.getClass().getName() + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public BooleanTypedValue getValueInternal(ExpressionState state) throws Evaluati
result = BooleanTypedValue.FALSE; // null is not an instanceof anything
}
else {
result = BooleanTypedValue.forValue(rightClass.isAssignableFrom(leftValue.getClass()));
result = BooleanTypedValue.forValue(rightClass.isInstance(leftValue));
}
this.type = rightClass;
if (rightOperand instanceof TypeReference) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public GeneratedKeyHolder(List<Map<String, Object>> keyList) {
Iterator<Object> keyIter = this.keyList.get(0).values().iterator();
if (keyIter.hasNext()) {
Object key = keyIter.next();
if (key == null || !(keyType.isAssignableFrom(key.getClass()))) {
if (key == null || !(keyType.isInstance(key))) {
throw new DataRetrievalFailureException(
"The generated key type is not supported. " +
"Unable to cast [" + (key != null ? key.getClass().getName() : null) +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,11 @@ void customErrorCodeTranslation() {

DataAccessException exFor4200 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 42000));
assertThat(exFor4200).as("Should have been translated").isNotNull();
assertThat(BadSqlGrammarException.class.isAssignableFrom(exFor4200.getClass())).as("Should have been instance of BadSqlGrammarException").isTrue();
assertThat(exFor4200).isInstanceOf(BadSqlGrammarException.class);

DataAccessException exFor2 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 2));
assertThat(exFor2).as("Should have been translated").isNotNull();
assertThat(TransientDataAccessResourceException.class.isAssignableFrom(exFor2.getClass())).as("Should have been instance of TransientDataAccessResourceException").isTrue();
assertThat(exFor2).isInstanceOf(TransientDataAccessResourceException.class);

DataAccessException exFor3 = sext.doTranslate("", "", new SQLException("Ouch", "42000", 3));
assertThat(exFor3).as("Should not have been translated").isNull();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ protected static IdGenerator getIdGenerator() {
if (value == null) {
return null;
}
if (!type.isAssignableFrom(value.getClass())) {
if (!type.isInstance(value)) {
throw new IllegalArgumentException("Incorrect type specified for header '" +
key + "'. Expected [" + type + "] but actual type is [" + value.getClass() + "]");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public List<MessageCondition<?>> getMessageConditions() {
@SuppressWarnings("unchecked")
public <T extends MessageCondition<T>> T getCondition(Class<T> messageConditionType) {
for (MessageCondition<?> condition : this.messageConditions) {
if (messageConditionType.isAssignableFrom(condition.getClass())) {
if (messageConditionType.isInstance(condition)) {
return (T) condition;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else if (MessageHeaderAccessor.class == paramType) {
}
else if (MessageHeaderAccessor.class.isAssignableFrom(paramType)) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
if (accessor != null && paramType.isAssignableFrom(accessor.getClass())) {
if (accessor != null && paramType.isInstance(accessor)) {
return accessor;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ else if (MessageHeaderAccessor.class == paramType) {
}
else if (MessageHeaderAccessor.class.isAssignableFrom(paramType)) {
MessageHeaderAccessor accessor = MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class);
if (accessor != null && paramType.isAssignableFrom(accessor.getClass())) {
if (accessor != null && paramType.isInstance(accessor)) {
return accessor;
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Object resolveArgument(MethodParameter parameter, Message<?> message) thr
Class<?> targetMessageType = parameter.getParameterType();
Class<?> targetPayloadType = getPayloadType(parameter, message);

if (!targetMessageType.isAssignableFrom(message.getClass())) {
if (!targetMessageType.isInstance(message)) {
throw new MethodArgumentTypeMismatchException(message, parameter, "Actual message type '" +
ClassUtils.getDescriptiveType(message) + "' does not match expected type '" +
ClassUtils.getQualifiedName(targetMessageType) + "'");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ protected String toHeaderName(String propertyName) {
if (value == null) {
return null;
}
if (!type.isAssignableFrom(value.getClass())) {
if (!type.isInstance(value)) {
if (logger.isDebugEnabled()) {
logger.debug("Skipping header '" + name + "': expected type [" + type + "], but got [" +
value.getClass() + "]");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,7 @@ private DataBuffer toDataBuffer(String value) {

Object value = result.block(Duration.ofSeconds(5));
if (value != null) {
Class<?> expectedType = param.getParameterType();
assertThat(expectedType.isAssignableFrom(value.getClass())).as("Unexpected return value type: " + value).isTrue();
assertThat(value).isInstanceOf(param.getParameterType());
}
return (T) value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void processHeadersToSend() {
Map<String, Object> map = this.messagingTemplate.processHeadersToSend(null);

assertThat(map).isNotNull();
assertThat(MessageHeaders.class.isAssignableFrom(map.getClass())).as("Actual: " + map.getClass()).isTrue();
assertThat(map instanceof MessageHeaders).as("Actual: " + map.getClass()).isTrue();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please convert ALL instanceof and type.isInstance() assertions in this commit to use assertThat(...).isInstance(...).

At a glance there are 7 or more such occurrences in this PR across various test files.


SimpMessageHeaderAccessor headerAccessor =
MessageHeaderAccessor.getAccessor((MessageHeaders) map, SimpMessageHeaderAccessor.class);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public static <T> T assertAndReturnModelAttributeOfType(ModelAndView mav, String
fail("Model attribute with name '" + modelName + "' is null");
}
assertTrue("Model attribute is not of expected type '" + expectedType.getName() + "' but rather of type '" +
obj.getClass().getName() + "'", expectedType.isAssignableFrom(obj.getClass()));
obj.getClass().getName() + "'", expectedType.isInstance(obj));
return (T) obj;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public static boolean hasAncestorOfType(Tag tag, Class<?> ancestorTagClass) {
}
Tag ancestor = tag.getParent();
while (ancestor != null) {
if (ancestorTagClass.isAssignableFrom(ancestor.getClass())) {
if (ancestorTagClass.isInstance(ancestor)) {
return true;
}
ancestor = ancestor.getParent();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class SimpleHandlerAdapter implements HandlerAdapter {

@Override
public boolean supports(Object handler) {
return WebHandler.class.isAssignableFrom(handler.getClass());
return handler instanceof WebHandler;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return handler instanceof WebHandler;
return (handler instanceof WebHandler);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ public Mono<Object> resolveArgument(
// This is done to enable early argument resolution here. When the Mono actually
// completes it is replaced in the model with the actual value.

if (Mono.class.isAssignableFrom(errors.getClass())) {
if (errors instanceof Mono) {
return ((Mono<?>) errors).cast(Object.class);
}
else if (Errors.class.isAssignableFrom(errors.getClass())) {
else if (errors instanceof Errors) {
return Mono.just(errors);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ protected NamedValueInfo createNamedValueInfo(MethodParameter parameter) {
parameter.getGenericParameterType() + " doesn't support empty values.");
return toAdapter.fromPublisher(Mono.empty());
}
if (parameter.getParameterType().isAssignableFrom(value.getClass())) {
if (parameter.getParameterType().isInstance(value)) {
return value;
}
ReactiveAdapter fromAdapter = getAdapterRegistry().getAdapter(value.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public WebSocketService getWebSocketService() {

@Override
public boolean supports(Object handler) {
return WebSocketHandler.class.isAssignableFrom(handler.getClass());
return handler instanceof WebSocketHandler;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return handler instanceof WebSocketHandler;
return (handler instanceof WebSocketHandler);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ private <T> T resolveValue(ServerWebExchange exchange, ResolvableType type) {
Object value = result.block(Duration.ofSeconds(5));

assertThat(value).isNotNull();
assertThat(param.getParameterType().isAssignableFrom(value.getClass())).as("Unexpected return value type: " + value.getClass()).isTrue();
assertThat(param.getParameterType().isInstance(value)).as("Unexpected return value type: " + value.getClass()).isTrue();

return (T) value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ private <T> T resolveValue(MethodParameter param, String body) {
Object value = result.block(Duration.ofSeconds(5));

assertThat(value).isNotNull();
assertThat(param.getParameterType().isAssignableFrom(value.getClass())).as("Unexpected return value type: " + value).isTrue();
assertThat(param.getParameterType().isInstance(value)).as("Unexpected return value type: " + value).isTrue();

return (T) value;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private <T> T resolveValue(MethodParameter param, String body) {
Object value = result.block(Duration.ofSeconds(5));

assertThat(value).isNotNull();
assertThat(param.getParameterType().isAssignableFrom(value.getClass()))
assertThat(param.getParameterType().isInstance(value))
.as("Unexpected return value type: " + value).isTrue();

//no inspection unchecked
Expand All @@ -248,7 +248,7 @@ private <T> T resolveValueWithEmptyBody(MethodParameter param) {
Object value = result.block(Duration.ofSeconds(5));

if (value != null) {
assertThat(param.getParameterType().isAssignableFrom(value.getClass()))
assertThat(param.getParameterType().isInstance(value))
.as("Unexpected parameter type: " + value).isTrue();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ private <T> T resolveArgument(MethodParameter param, MultipartBodyBuilder builde
Object value = result.block(Duration.ofSeconds(5));

assertThat(value).isNotNull();
assertThat(param.getParameterType().isAssignableFrom(value.getClass())).isTrue();
assertThat(param.getParameterType().isInstance(value)).isTrue();
return (T) value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ void resolverArgument() {
param = this.testMethod.arg(Mono.class, WebSession.class);
actual = this.resolver.resolveArgument(param, context, exchange).block();
assertThat(actual).isNotNull();
assertThat(Mono.class.isAssignableFrom(actual.getClass())).isTrue();
assertThat(actual instanceof Mono).isTrue();
assertThat(((Mono<?>) actual).block()).isSameAs(session);

param = this.testMethod.arg(Single.class, WebSession.class);
actual = this.resolver.resolveArgument(param, context, exchange).block();
assertThat(actual).isNotNull();
assertThat(Single.class.isAssignableFrom(actual.getClass())).isTrue();
assertThat(actual instanceof Single).isTrue();
assertThat(((Single<?>) actual).blockingGet()).isSameAs(session);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -579,11 +579,11 @@ private ContextSnapshotHelper(@Nullable ContextSnapshotFactory factory) {

@SuppressWarnings("ReactiveStreamsUnusedPublisher")
public Object writeReactorContext(Object returnValue) {
if (Mono.class.isAssignableFrom(returnValue.getClass())) {
if (returnValue instanceof Mono) {
ContextSnapshot snapshot = this.snapshotFactory.captureAll();
return ((Mono<?>) returnValue).contextWrite(snapshot::updateContext);
}
else if (Flux.class.isAssignableFrom(returnValue.getClass())) {
else if (returnValue instanceof Flux) {
ContextSnapshot snapshot = this.snapshotFactory.captureAll();
return ((Flux<?>) returnValue).contextWrite(snapshot::updateContext);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private <A> List<A> getMatchingAdvice(MethodParameter parameter, Class<? extends
}
advice = adviceBean.resolveBean();
}
if (adviceType.isAssignableFrom(advice.getClass())) {
if (adviceType.isInstance(advice)) {
result.add((A) advice);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ public int getOrder() {

@Override
public boolean supports(Object handler) {
return handler != null && MyHandler.class.isAssignableFrom(handler.getClass());
return handler instanceof MyHandler;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return handler instanceof MyHandler;
return (handler instanceof MyHandler);

}

@Override
Expand All @@ -268,7 +268,7 @@ public static class MyDummyAdapter extends ApplicationObjectSupport implements H

@Override
public boolean supports(Object handler) {
return handler != null && MyHandler.class.isAssignableFrom(handler.getClass());
return handler instanceof MyHandler;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return handler instanceof MyHandler;
return (handler instanceof MyHandler);

}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (other == null || !WebSocketExtension.class.isAssignableFrom(other.getClass())) {
if (other == null || !(other instanceof WebSocketExtension)) {
return false;
}
WebSocketExtension otherExt = (WebSocketExtension) other;
Expand Down