Skip to content

Conversation

scordio
Copy link
Contributor

@scordio scordio commented Aug 11, 2025

See #32683.

Deliverables

  • Annotate all existing Assert implementations
  • Build ArchUnit rule to ensure consistency

@snicoll
Copy link
Member

snicoll commented Aug 11, 2025

See #32683 (comment)

@snicoll snicoll added the status: on-hold We can't start working on this issue yet label Aug 11, 2025
@scordio scordio marked this pull request as draft August 11, 2025 07:30
@scordio
Copy link
Contributor Author

scordio commented Aug 11, 2025

As I need to extend Checkstyle's import-control.xml, would it be fine to add a top-level allow statement close to:

<allow class="org.springframework.lang.Contract" />

or should I define a more fine-grained rule, restricting it to the following packages?

  • org.springframework.boot.test.context.assertj
  • org.springframework.boot.test.json

@snicoll
Copy link
Member

snicoll commented Aug 11, 2025

would it be fine to add a top-level allow statement close to

Yep. The intention is to restrict only to certain AssertJ entry point and this is one of them so I think that's ok.

@snicoll
Copy link
Member

snicoll commented Sep 10, 2025

@scordio how is it going, anything I can do to help?

@scordio
Copy link
Contributor Author

scordio commented Sep 10, 2025

Apologies, life happened and this fell off my radar! 🤦

If not in a rush, I'm happy to continue on it over the weekend.

@wilkinsona
Copy link
Member

Thanks, @scordio. There's no rush.

@scordio scordio force-pushed the gh-32683-CheckReturnValue branch 2 times, most recently from 76f6b34 to 934b746 Compare September 14, 2025 12:21
@scordio scordio changed the title Annotate ApplicationContextAssert methods with @CheckReturnValue Decorate all Assert implementations with @CheckReturnValue Sep 14, 2025
@scordio
Copy link
Contributor Author

scordio commented Sep 14, 2025

When building the project locally, I get two NullAway errors on :core:spring-boot:compileJava:

/Users/stefano/Projects/spring-boot/core/spring-boot/src/main/java/org/springframework/boot/context/properties/bind/ValueObjectBinder.java:424: error: [NullAway] Method returns @Nullable String @Nullable [], but overridden method returns String [], which has mismatched type parameter nullability
		public @Nullable String @Nullable [] getParameterNames(Constructor<?> constructor) {
		                                     ^
    (see http://t.uber.com/nullaway )
/Users/stefano/Projects/spring-boot/core/spring-boot/src/main/java/org/springframework/boot/logging/structured/StructuredLogFormatterFactory.java:240: error: [NullAway] referenced method returns @Nullable, but functional interface method java.util.function.Function.apply(T) returns @NonNull
					ArgumentResolver.from(StructuredLogFormatterFactory.this.instantiator::getArg));
					                      ^
    (see http://t.uber.com/nullaway )

but the CI seems fine 🤔

@snicoll
Copy link
Member

snicoll commented Sep 14, 2025

@scordio you need Java 24 to build the project

@scordio

This comment was marked as outdated.

@scordio scordio force-pushed the gh-32683-CheckReturnValue branch from 934b746 to df47244 Compare September 14, 2025 21:20
Comment on lines +147 to +150
private static DescribedPredicate<JavaMethod> dontReturnSelfType() {
return DescribedPredicate.describe("don't return self type",
(method) -> !method.getRawReturnType().equals(method.getOwner()));
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This doesn't play well with overridden methods:

Architecture Violation [Priority: MEDIUM] - Rule 'methods that are declared in classes that implement org.assertj.core.api.Assert and are public and don't return self type should be annotated with @CheckReturnValue' was violated (4 times):
Method <org.springframework.boot.test.json.JsonContentAssert.isEqualTo(java.lang.Object)> is not annotated with @CheckReturnValue in (JsonContentAssert.java:56)
Method <org.springframework.boot.test.json.JsonContentAssert.isEqualTo(java.lang.Object)> is not annotated with @CheckReturnValue in (JsonContentAssert.java:56)
Method <org.springframework.boot.test.json.JsonContentAssert.isNotEqualTo(java.lang.Object)> is not annotated with @CheckReturnValue in (JsonContentAssert.java:56)
Method <org.springframework.boot.test.json.JsonContentAssert.isNotEqualTo(java.lang.Object)> is not annotated with @CheckReturnValue in (JsonContentAssert.java:56)

I'll continue looking at it tomorrow.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: on-hold We can't start working on this issue yet status: waiting-for-triage An issue we've not yet triaged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants