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

Change AssumptionViolatedException to not set the cause to null; fixes issue #494 #985

Merged

Conversation

kcooney
Copy link
Member

@kcooney kcooney commented Sep 6, 2014

No description provided.

@marcphilipp
Copy link
Member

I think we should ask @mmichaelis who reported #494 to take a look and make sure we solve his problem, shouldn't we?

@mmichaelis
Copy link
Contributor

Thanks for referring to me... and actually thanks for fixing! Yes, I think the suggested solution works as it does not overwrite "this" cause in Throwable by accident.

The only thing to add: I think a test-case is missing which would show the failure in the previous version. Suggested test:

@Test
public void causeCanBeInitializedLater() {
  Throwable cause = new Exception();
  AssumptionViolatedException e = new AssumptionViolatedException("invalid number");
  // Old behavior: Following statement would raise IllegalStateException: "Can't overwrite cause"
  // triggered by Throwable#initCause().
  e.initCause(cause);
  assertThat(e.getCause(), is(cause));
}

@kcooney
Copy link
Member Author

kcooney commented Sep 8, 2014

@mmichaelis I would think your proposed test would be covered by the tests that @marcin-lawrowski wrote that checked for a null cause. Am I missing something?

@mmichaelis
Copy link
Contributor

@kcooney No, that's not enough as you cannot distinguish via getCause() the states

  • cause unset (Throwable will mark this state with cause=this) from
  • cause set to null
    as can be seen in Throwable both states would reveal null as result:
public Throwable getCause() {
  return (cause==this ? null : cause);
}

@kcooney kcooney force-pushed the AssumptionViolatedException-cause branch from 6f9e4c0 to daa46e4 Compare September 9, 2014 16:01
@kcooney
Copy link
Member Author

kcooney commented Sep 9, 2014

@mmichaelis got it. Updated one of the tests we added to call initCause and check that the cause was set.

@mmichaelis
Copy link
Contributor

@kcooney Great. Thanks a lot!

kcooney added a commit that referenced this pull request Sep 10, 2014
Change AssumptionViolatedException to not set the cause to null; fixes issue #494
@kcooney kcooney merged commit afdbe56 into junit-team:master Sep 10, 2014
@kcooney kcooney deleted the AssumptionViolatedException-cause branch September 10, 2014 16:39
@marcphilipp
Copy link
Member

@kcooney We should mention this fix in the release notes. I have already moved them from the wiki into the repository. Do you have time to do it?

@kcooney
Copy link
Member Author

kcooney commented Sep 11, 2014

@marcphilipp Filed #987 to update the release notes.

@marcphilipp
Copy link
Member

Great, thanks!

marcphilipp added a commit that referenced this pull request Sep 11, 2014
Update release notes to include pulls #818 and #985
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.

3 participants