Skip to content

Ensuring nullability contracts #1387

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 12, 2025
Merged

Ensuring nullability contracts #1387

merged 1 commit into from
Aug 12, 2025

Conversation

scottf
Copy link
Contributor

@scottf scottf commented Aug 11, 2025

  • ConsumerInfo
  • StreamInfo
  • Unit tests reflect tightening
  • Address IDE review notes

- ConsumerInfo
- StreamInfo
- Unit tests reflect tightening
- Address IDE review notes
@@ -17,7 +17,7 @@
* Consume Options are provided to customize the consume operation.
*/
public class ConsumeOptions extends BaseConsumeOptions {
public static ConsumeOptions DEFAULT_CONSUME_OPTIONS = ConsumeOptions.builder().build();
public static final ConsumeOptions DEFAULT_CONSUME_OPTIONS = ConsumeOptions.builder().build();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should have been final

@@ -26,7 +26,7 @@
* Fetch Consume Options are provided to customize the fetch operation.
*/
public class FetchConsumeOptions extends BaseConsumeOptions {
public static FetchConsumeOptions DEFAULT_FETCH_OPTIONS = FetchConsumeOptions.builder().build();
public static final FetchConsumeOptions DEFAULT_FETCH_OPTIONS = FetchConsumeOptions.builder().build();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should have been final

@@ -31,7 +32,7 @@ public abstract class ApiResponse<T> {
protected final JsonValue jv;

private final String type;
private final Error error;
private Error error;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

make this not final to support the subclass constructor setting it.
This is part of the effort to ensure that ConsumerInfo and StreamInfo can indicate they are an error if they don't parse correctly, because they can't throw an exception during construction, they didn't before.

pushBound = readBoolean(jv, PUSH_BOUND);

timestamp = readDate(jv, TIMESTAMP);
if (hasError()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it's an already error there is no need to parse, but since vars are final we do need to set them.

}
else {
JsonValue jvConfig = nullValueIsError(jv, CONFIG, JsonValue.EMPTY_MAP) ;
configuration = ConsumerConfiguration.builder().jsonValue(jvConfig).build();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't be null, but turns the object into an error. This would never happen except with data from somewhere other than the server, and all this is to just match the nullability contracts. Same with stream/name/created below.

sourceInfos = SourceInfo.optionalListOf(readValue(jv, SOURCES));
alternates = StreamAlternate.optionalListOf(readValue(jv, ALTERNATES));
timestamp = readDate(jv, TIMESTAMP);
if (hasError()) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

When it's an already error there is no need to parse, but since vars are final we do need to set them.

JsonValue jvConfig = nullValueIsError(jv, CONFIG, JsonValue.NULL);
config = (jvConfig == JsonValue.NULL)
? StreamConfiguration.builder().name(UNDEFINED).build()
: StreamConfiguration.instance(jvConfig);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

can't be null, but turns the object into an error. This would never happen except with data from somewhere other than the server, and all this is to just match the nullability contracts. Same with create time below.

@@ -41,7 +41,7 @@ public enum ManageResult {MESSAGE, STATUS_HANDLED, STATUS_TERMINUS, STATUS_ERROR

protected long lastStreamSeq;
protected long lastConsumerSeq;
protected AtomicLong lastMsgReceivedNanoTime;
protected final AtomicLong lastMsgReceivedNanoTime;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

should have been final

deliverPolicy,
headersOnly,
fromRevision,
getHandler(watcher, !ignoreDeletes),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ide suggested and then helped me refactor the handler to a method

deliverPolicy,
headersOnly,
ULONG_UNSET,
getHandler(watcher, !ignoreDeletes),
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The ide suggested and then helped me refactor the handler to a method

@scottf scottf requested a review from MauriceVanVeen August 11, 2025 20:52
Copy link
Member

@MauriceVanVeen MauriceVanVeen left a comment

Choose a reason for hiding this comment

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

LGTM

@scottf scottf merged commit 38a3daa into main Aug 12, 2025
5 checks passed
@scottf scottf deleted the info-nullability branch August 12, 2025 11:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants