question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Awaitility hiding exceptions on the same thread

See original GitHub issue

This is a small program that demonstrates the behavior I’m seeing that appears to be a bug.

Actual behavior: When this runs it exits and prints IllegalArgumentException stack trace like a normal java program. The weird behavior is if you comment out the line .dontCatchUncaughtExceptions(), it will exit with status code 1 and not print the exception.

Expected behavior: I would expect awaitility to not affect exceptions thrown in the same thread and outside its until() {} block.

Version: <groupId>org.awaitility</groupId> <artifactId>awaitility</artifactId> <version>3.1.2</version>

public static void main(final String... args) throws Exception {
        final AtomicInteger count = new AtomicInteger(0);
        await()
                .dontCatchUncaughtExceptions()
                .ignoreExceptionsMatching(instanceOf(IOException.class))
                .atMost(3, TimeUnit.MINUTES)
                .until(() -> {
                    count.incrementAndGet();
                    return count.get() > 3;
                });

        if (true) {
            System.out.println("throwing an exception");
            throw new IllegalArgumentException("broken");
        }
        System.out.println("Already exited so you won't see this");
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
grofolicommented, Jan 1, 2020

I opened a PR few minutes ago. Please be aware that writing a unit test similar to the main method below is not easily possible, because the JUnit Framework has an own Exception handling. Therefore I decided to test an implementation detail in the unit test, namely the reset of the original defaultUncaughtExceptionHandler.

The following main method throws an IllegalArgumentException exception, which proves that the Awaitility does NOT hide exception on the main thread anymore.

public static void main(final String... args) throws Exception {
        final AtomicInteger count = new AtomicInteger(0);
        await()
                .until(() -> {
                    count.incrementAndGet();
                    return count.get() > 3;
                });

        if (true) {
            throw new IllegalArgumentException("broken");
        }
    } 
0reactions
johanhalebycommented, Jan 3, 2020

Thanks for trying it out, reviewing and reminding me Oliver! 😃 I’ll try release 4.0.2 now. I can’t thank you enough for your efforts on this release!

On Thu, Jan 2, 2020 at 8:38 PM Oliver Grof notifications@github.com wrote:

@johanhaleby https://github.com/johanhaleby I tried a little bit some simple usages of the libary today and they were working fine. When do you plan to release it? FYI: There is a PR open that I reviewed and suggested a minor change for @metatype https://github.com/metatype. Do you want to include that in the next version as well or do you want to release the current 4.0.2-SNAPSHOT? #153 https://github.com/awaitility/awaitility/pull/153

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/awaitility/awaitility/issues/152?email_source=notifications&email_token=AABNVFLQFBVIADPUE7LLXPDQ3Y7C5A5CNFSM4J2D2PHKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEH7F5NI#issuecomment-570318517, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABNVFINQ4OKQRSYBDZC3P3Q3Y7C5ANCNFSM4J2D2PHA .

Read more comments on GitHub >

github_iconTop Results From Across the Web

Asynchronous tests, the Awaitility and uncaught exceptions ...
One example of such test: @Test public void asyncMethodListener() throws Exception { // Arrange originalThreadName = Thread.currentThread().
Read more >
Developers - Awatility-4.0.2 hiding exceptions on the same thread -
I was under an impression that 'dontCatchUncaughtExceptions' should throw the RuntimeException when occurred. However, it skips throwing the exception over ...
Read more >
Awaitility (Awaitility 3.0.0 API) - Javadoc.io
Instruct Awaitility to catch uncaught exceptions from other threads by default. This is useful in multi-threaded systems when you want your test to...
Read more >
Code Smell: "Thread.sleep" should not be used in tests
Using Thread.sleep in a test is just generally a bad idea. It creates brittle tests that can fail unpredictably depending on environment ("Passes...
Read more >
Exception Handling in Java - Baeldung
Checked exceptions; Unchecked exceptions / Runtime exceptions; Errors. Runtime and unchecked exceptions refer to the same thing. We can often ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found