Skip to content

Conversation

@izeye
Copy link
Contributor

@izeye izeye commented Jul 17, 2025

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
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
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) {
Copy link
Contributor Author

@izeye izeye Jul 17, 2025

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.

@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
Copy link
Member

jonatan-ivanov commented Jul 17, 2025

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
11 checks passed
@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