-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Throw AssumptionViolatedException when single null is passed to Assum… #1380
Conversation
…e.assumeNotNull(Object... objects) method Previous implementation threw NullPointerException when single null argument was passed: java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.Arrays$ArrayList.<init>(Arrays.java:3813) at java.util.Arrays.asList(Arrays.java:3800)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
BTW, are you absolutely sure the test would fail without the code changes? I would think you would need to pass in a |
Kevin, Out of those two:
only the first one fails with:
|
Also it's fair to say that this invocation produces warning:
More details here: http://stackoverflow.com/a/4028086 |
Based on that stackoverflow thread, I'm tempted to say that the current behavior is fine. It should be rare to explicitly pass in null
here
To extrapolate, the following is the only way to get a NPE out of this method:
and
The first isn't clearly a valid use of this API. The second should be exceedingly rare. |
Kevin, You are correct. This is much more subtle than I originally thought. If I was using Java I would have never caught this. Reproducing this in Groovy is, however, much simpler:
FYI in Java invocation on any type of Array will throw e.g.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! I've added a two inline comments requesting changes.
@@ -111,6 +111,16 @@ public void assumeNotNullThrowsException() { | |||
} | |||
|
|||
@Test | |||
public void assumeNotNullSingleNullThrowsException() { | |||
try { | |||
assumeNotNull(null); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a cast to Object[]
here.
@@ -79,6 +79,7 @@ public static void assumeFalse(String message, boolean b) { | |||
* If called with one or more null elements in <code>objects</code>, the test will halt and be ignored. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please update the Javadoc:
If called with a {@code null} array or one or more {@code null} elements in {@code objects},
the test will halt and be ignored.
Thanks! Could you please update the release notes? |
…e.assumeNotNull(Object... objects) method Previous implementation threw `NullPointerException` when single `null` argument was passed: java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.Arrays$ArrayList.<init>(Arrays.java:3813) at java.util.Arrays.asList(Arrays.java:3800) Fixes junit-team#1380
…e.assumeNotNull(Object... objects) method Previous implementation threw `NullPointerException` when single `null` argument was passed: java.lang.NullPointerException at java.util.Objects.requireNonNull(Objects.java:203) at java.util.Arrays$ArrayList.<init>(Arrays.java:3813) at java.util.Arrays.asList(Arrays.java:3800) Fixes junit-team#1380
…e.assumeNotNull(Object... objects) method
Previous implementation threw NullPointerException when single null argument was passed:
java.lang.NullPointerException
at java.util.Objects.requireNonNull(Objects.java:203)
at java.util.Arrays$ArrayList.(Arrays.java:3813)
at java.util.Arrays.asList(Arrays.java:3800)