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

[SUREFIRE-1851] Prevent NPE in SmartStackTraceParser #320

Merged
merged 1 commit into from
Oct 7, 2020
Merged

[SUREFIRE-1851] Prevent NPE in SmartStackTraceParser #320

merged 1 commit into from
Oct 7, 2020

Conversation

domdomegg
Copy link
Contributor

JIRA: https://issues.apache.org/jira/browse/SUREFIRE-1851

SmartStackTraceParser is used in various places to parse throwables. However, if the throwable stack trace is null it will throw an NPE itself. This can cause test runners to fail in unexpected ways, which in the worst case can lead to false success test results and passing builds despite the test actually failing.

An exception with a null stacktrace sounds odd, but is easy to do by mocking an exception with frameworks like Mockito. While people probably shouldn't be mocking exceptions, it definitely can and does happen. Can be reproduced with https://github.com/domdomegg/surefire-1851-demo

This is my first PR to the Apache project, apologies if I've gotten anything wrong - I've tried to follow the contributing guidelines as best I can, but do let me know if something needs changing :)

}

@Override
public synchronized Throwable getCause()
Copy link
Contributor

Choose a reason for hiding this comment

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

Why synchronized?

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 is no need for it to be synchronized, good catch. I will remove this.

@Tibor17
Copy link
Contributor

Tibor17 commented Oct 6, 2020

Pls squash the commits finally. Thx.

}

private static List<StackTraceElement> focusOnClass( StackTraceElement[] stackTrace, Class<?> clazz )
{
List<StackTraceElement> result = new ArrayList<>();
if ( stackTrace == null )
{
Copy link
Contributor

Choose a reason for hiding this comment

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

Pls use Collections.emptyList() instead, and move the ArrayList down. Thx

@domdomegg
Copy link
Contributor Author

Many thanks for your review 🙌

I believe I have made the required changes, including:

  • removing unnecessary synchronized
  • squashing the commits into one final commit (0505338)
  • moving the array list constructor past the if statement, and using Collections.emptyList() instead

@Tibor17
Copy link
Contributor

Tibor17 commented Oct 6, 2020 via email

@Tibor17 Tibor17 merged commit 08163fa into apache:master Oct 7, 2020
@Tibor17
Copy link
Contributor

Tibor17 commented Oct 7, 2020

@domdomegg
Thx for contributing.

@domdomegg domdomegg deleted the surefire-1851-domdomegg-patch-1 branch October 10, 2020 15:34
@domdomegg
Copy link
Contributor Author

Thanks for your review and help with this :)

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