Skip to content

Replace isAssignableFrom() with isInstance() where feasible#36899

Open
quaff wants to merge 1 commit into
spring-projects:mainfrom
quaff:patch-137
Open

Replace isAssignableFrom() with isInstance() where feasible#36899
quaff wants to merge 1 commit into
spring-projects:mainfrom
quaff:patch-137

Conversation

@quaff

@quaff quaff commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jun 11, 2026
@sbrannen sbrannen added the type: task A general task label Jun 11, 2026
@sbrannen

This comment was marked as outdated.

@sbrannen sbrannen self-assigned this Jun 11, 2026
@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jun 11, 2026
@sbrannen sbrannen added this to the 7.1.0-M1 milestone Jun 11, 2026
@quaff

quaff commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Out of curiosity, how did you come across all of these?

Did you use a special IDE check, AI agent support, ...?

Replace \.isAssignableFrom\((.+)\.getClass\(\)\) with .isInstance($1).

@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 12, 2026

@sbrannen sbrannen left a comment

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.

Thanks for making the requested change.

Now I've requested a few additional minor changes.

@sbrannen sbrannen added status: waiting-for-feedback We need additional information before we can continue and removed status: feedback-provided Feedback has been provided labels Jun 12, 2026
@sbrannen sbrannen changed the title Replace isAssignableFrom with isInstance where feasible Replace isAssignableFrom() with isInstance() where feasible Jun 12, 2026
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
@quaff

quaff commented Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for making the requested change.

Now I've requested a few additional minor changes.

Updated, please review.

@quaff quaff requested a review from sbrannen June 12, 2026 09:03
@spring-projects-issues spring-projects-issues added status: feedback-provided Feedback has been provided and removed status: waiting-for-feedback We need additional information before we can continue labels Jun 12, 2026
@sbrannen sbrannen added type: enhancement A general enhancement and removed status: feedback-provided Feedback has been provided type: task A general task labels Jun 12, 2026

@sbrannen sbrannen left a comment

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.

You missed several of the test assertions. So I've pointed those out as well as some other minor changes.

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);

@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
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
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
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);


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.

@sbrannen sbrannen added the status: waiting-for-feedback We need additional information before we can continue label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

status: waiting-for-feedback We need additional information before we can continue type: enhancement A general enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants