Skip to content
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

Java: throw a more appropriate exception. #199

Merged
merged 1 commit into from
Jul 10, 2024

Conversation

overcat
Copy link
Contributor

@overcat overcat commented Jun 27, 2024

This PR is very simple, I think it's more appropriate to throw an IllegalArgumentException here.

Copy link
Member

@leighmcculloch leighmcculloch left a comment

Choose a reason for hiding this comment

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

👍🏻 The change looks good to me. One question inline. Let me know and if you want to merge it as is happy to do that.

throw new InvalidClassException("String length " + size + " exceeds max size " + maxSize);
throw new IllegalArgumentException("String length " + size + " exceeds max size " + maxSize);
Copy link
Member

@leighmcculloch leighmcculloch Jul 10, 2024

Choose a reason for hiding this comment

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

Because it's the size inside the stream, and not the maxSize variable, that is illegal, I'm not sure I'd class this as an illegal argument exception (IAE) because the arguments are actually okay it's an issue with data available on the stream and not the function arguments.

BufferOverflowException (BOE) might be more appropriate?

Happy to merge this if you think IAE is the most appropriate exception over BOE. Wdyt?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @leighmcculloch, BOE is also a suitable choice, but I still prefer to use IAE here.

  • In the given code, the exception is triggered when one parameter (size) exceeds another parameter (maxSize). This aligns well with the definition of IAE, which is used when a method receives an inappropriate or invalid argument. In this case, the size being greater than maxSize is due to an incorrect size parameter contained within the passed-in stream.
  • IAE is a very common and familiar exception type in Java, widely used to represent various invalid arguments or inappropriate conditions. By using IAE, other developers can quickly understand and handle the exception.

@leighmcculloch leighmcculloch merged commit ffe4ba5 into stellar:master Jul 10, 2024
3 checks passed
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