Skip to content

aggregate exception improvement #1188

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 4 commits into from
May 3, 2022
Merged

Conversation

csviri
Copy link
Collaborator

@csviri csviri commented May 2, 2022

Overriding toString. Adding the first exception as cause - maybe would be better to override printStackTrace to handle the causes? Respectively getOurStackTrace in Throwable to have it nicer?

@csviri csviri self-assigned this May 2, 2022
private final List<Exception> causes;

public AggregatedOperatorException(String message, Exception... exceptions) {
super(message);
this.causes = exceptions != null ? Arrays.asList(exceptions) : Collections.emptyList();
super(message, exceptions[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

This might NPE if no exception is passed.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

pushed with null check

}

public AggregatedOperatorException(String message, List<Exception> exceptions) {
super(message);
this.causes = exceptions != null ? exceptions : Collections.emptyList();
super(message, exceptions.get(0));
Copy link
Collaborator

Choose a reason for hiding this comment

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

Same, we need to check that the given parameter is not null…


public class AggregatedOperatorException extends OperatorException {

private final List<Exception> causes;

public AggregatedOperatorException(String message, Exception... exceptions) {
super(message, exceptions[0]);
super(message, Objects.requireNonNull(exceptions)[0]);
Copy link
Collaborator

Choose a reason for hiding this comment

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

That doesn't help, actually, since this still will throw an NPE if exceptions isn't present. With varargs, it's a definite possibility, though, granted, creating an AggregatedOperatorException and not passing any exceptions is probably expected to fail…

@sonarqubecloud
Copy link

sonarqubecloud bot commented May 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

0.0% 0.0% Coverage
0.0% 0.0% Duplication

@csviri csviri merged commit 6428502 into main May 3, 2022
@csviri csviri deleted the aggregate-exception-improvement branch May 3, 2022 06:40
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