Skip to content

Improve nullability for gauges - #6546

Merged
jonatan-ivanov merged 1 commit into
micrometer-metrics:mainfrom
izeye:contracts-for-gauges
Jul 17, 2025
Merged

jonatan-ivanov merged 1 commit into
micrometer-metrics:mainfrom
izeye:contracts-for-gauges

Conversation

@izeye

@izeye izeye commented Jul 17, 2025

Copy link
Copy Markdown
Contributor

This PR changes to use @Contract to improve nullability for gauges.

@izeye
izeye force-pushed the contracts-for-gauges branch 2 times, most recently from 3b2355a to 42023ac Compare July 17, 2025 14:43
* @return The number that was passed in so the registration can be done as part of an
* assignment statement.
*/
@Contract("_, _, !null -> !null")

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There are some inconsistencies including this. If the state object (number) being non-null is intentional, dropping @Nullable seems to be better.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I just dropped @Nullable annotations for these cases instead.

* assignment statement.
*/
@Contract("_, _, !null, _ -> !null")
public static <T> @Nullable T gauge(String name, Iterable<Tag> tags, T obj, ToDoubleFunction<T> valueFunction) {

@izeye izeye Jul 17, 2025 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

There is another inconsistency: the state object in the corresponding method in the MeterRegistry is nullable while this state object (obj) is not nullable.

Signed-off-by: Johnny Lim <izeye@naver.com>
@izeye
izeye force-pushed the contracts-for-gauges branch from 42023ac to b07ee6b Compare July 17, 2025 15:19
@izeye izeye changed the title Use @Contract to improve nullability for gauges Improve nullability for gauges Jul 17, 2025
@jonatan-ivanov

jonatan-ivanov commented Jul 17, 2025 •

Copy link
Copy Markdown
Member

I think this is definitely an improvement over what we have now but we might need to revert parts of this:

/cc @shakuzen

@jonatan-ivanov jonatan-ivanov added this to the 1.16.0-M2 milestone Jul 17, 2025
@jonatan-ivanov
jonatan-ivanov merged commit b13ea28 into micrometer-metrics:main Jul 17, 2025
@jonatan-ivanov jonatan-ivanov added enhancement A general enhancement module: micrometer-core An issue that is related to our core module labels Jul 17, 2025
@izeye
izeye deleted the contracts-for-gauges branch July 18, 2025 01:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement A general enhancement module: micrometer-core An issue that is related to our core module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants