Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8864945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:22:51+00:00 2026-06-14T16:22:51+00:00

It’s been ages since I engaged in single combat with a JVM, and I

  • 0

It’s been ages since I engaged in single combat with a JVM, and I think I’ve forgotten something.

Got some code that has a ton of assertions, none with custom messages, just plain old assert some_condition; I’ve verified that -ea is being passed to the VM, and double-checked programmatically at startup that assertions are in face enabled.

Higher up the call chain is code that looks like this:

try {
    start_the_deeply_nested_stuff();
}
catch (Throwable e) {
    do stuff with e.getMessage()
}

The docs for AssertionError say that it’s descended from Throwable, and that it’s always constructed with the asserted expression as the ctor argument (after being converted to a string). I feel like I should be able to call getMessage() here and get something useful back, like “assertion failed on file X line Y because your code sucks”.

Instead, getMessage() returns null. The only way I’ve been able to figure out that an assertion is being triggered at all is by looping over e.getStackTrace() and tracking down line numbers.

What’s up with getMessage? Isn’t AssertionError always supposed to include something about the condition which triggered it?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T16:22:52+00:00Added an answer on June 14, 2026 at 4:22 pm

    Isn’t AssertionError always supposed to include something about the condition which triggered it?

    Apparently not – based on the docs.

    The expression

    assert args != null;
    

    will throw an AssertionError with no detail message (if args is null)

    assert args != null : "Arguments must not be null";
    

    will throw an AssertionError with the detail message Arguments must not be null

    I sympathize. It would be really cool if the compiler was smart enough to take an expression like

    assert args != null;
    

    and throw an AssertionError with the message “args != null” but I guess that’s not how it works.

    I suppose you could write a script to go through all your old code, detect assert expressions and replace them with something like:

    assert <expression> : "<text of expression>";
    

    such as

    assert args != null : "args != null";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a string that has curly quotes in it. I'd like to replace
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a small JavaScript validation script that validates inputs based on Regex. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.