Skip to content

Add assertions enabled helper#24834

Merged
jasontedor merged 2 commits intoelastic:masterfrom
jasontedor:assertions-enabled
May 23, 2017
Merged

Add assertions enabled helper#24834
jasontedor merged 2 commits intoelastic:masterfrom
jasontedor:assertions-enabled

Conversation

@jasontedor
Copy link
Copy Markdown
Member

Today in the code base we have lots of ugly code blocks like:

  boolean assertionsEnabled = false;
  assert assertionsEnabled = true;
  if (assertionsEnabled) {
    // something
  }

These are a nuisance. Instead, we can do this in exactly one place and replace these blocks with

  if (Assertions.ENABLED) {
    // something
  }

The cool thing here is that since this is a static final field, the JIT can optimize away the check at runtime if assertions are disabled.

Today in the code base we have lots of ugly code blocks like:

  boolean assertionsEnabled = false;
  assert assertionsEnabled = true;
  if (assertionsEnabled) {
    // something
  }

These are a nuisance. Instead, we can do this in exactly one place and
replace these blocks with

  if (Assertions.ENABLED) {
    // something
  }

The cool thing here is that since this is a static final field, the JIT
can optimize away the check at runtime if assertions are disabled.
Copy link
Copy Markdown

@abeyad abeyad left a comment

Choose a reason for hiding this comment

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

LGTM, nice

Copy link
Copy Markdown
Contributor

@bleskes bleskes left a comment

Choose a reason for hiding this comment

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

Cool.

@bleskes
Copy link
Copy Markdown
Contributor

bleskes commented May 23, 2017

This can also go to 5.x, no?

@jasontedor jasontedor merged commit c179c6a into elastic:master May 23, 2017
jasontedor added a commit that referenced this pull request May 23, 2017
Today in the code base we have lots of ugly code blocks like:

  boolean assertionsEnabled = false;
  assert assertionsEnabled = true;
  if (assertionsEnabled) {
    // something
  }

These are a nuisance. Instead, we can do this in exactly one place and
replace these blocks with

  if (Assertions.ENABLED) {
    // something
  }

The cool thing here is that since this is a static final field, the JIT
can optimize away the check at runtime if assertions are disabled.

Relates #24834
@jasontedor
Copy link
Copy Markdown
Member Author

Thanks @abeyad and @bleskes. I backported this to 5.x too.

@jasontedor jasontedor deleted the assertions-enabled branch May 23, 2017 13:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants