Skip to content

Conversation

@capistrant
Copy link
Contributor

@capistrant capistrant commented Nov 14, 2025

Description

If hydrants is empty here, it can lead to an IAE creating a sublist of hydrants with invalid indices.



This PR has:

  • been self-reviewed.
  • added documentation for new or modified features or behaviors.
  • a release note entry in the PR description.
  • added Javadocs for most classes and all non-trivial methods. Linked related entities via Javadoc links.
  • added or updated version, license, or notice information in licenses.yaml
  • added comments explaining the "why" and the intent of the code wherever would not be obvious for an unfamiliar reader.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage is met.
  • added integration tests.
  • been tested in a test Druid cluster.

bytesPersisted += sink.getBytesInMemory();

final int limit = sink.isWritable() ? hydrants.size() - 1 : hydrants.size();
final int limit = sink.isWritable() ? Integer.max(0, hydrants.size() - 1) : hydrants.size();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to have a small UT for this?

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 couldn't figure out how to accomplish it. So for full disclosure the test case I came up with is courtesy of Claude coming up with a way to force the empty list of hydrants scenario. Confirmed that without the fix it is an IAE and with the change, no exception.

Comment on lines +2549 to +2555
/**
* Tests an edge case where a writable sink exists but has no hydrants.
* <p>
* The test scenario is somewhat unrealistic, but we are trying to prevent a regression because this issue was seen in
* the wild and resulted in failed indexing tasks due to an IAE.
* </p>
*/
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the javadoc here can be omitted.
Also, since it was already reported, I think it is a valid scenario.

* </p>
*/
@Test
public void testPersistAllWithEmptySink() throws Exception
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: update the method name to reflect the expected behaviour with the suffix IsNoop or DoesNotFail, etc.

Suggested change
public void testPersistAllWithEmptySink() throws Exception
public void testPersistAllWithEmptySinkIsNoop() throws Exception

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants