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

StackOverflowError in addKeyValue is fatal #448

Open
monnetchr opened this issue Jan 20, 2025 · 0 comments
Open

StackOverflowError in addKeyValue is fatal #448

monnetchr opened this issue Jan 20, 2025 · 0 comments

Comments

@monnetchr
Copy link

Slf4j logs [FAILED toString()] when a StackOverflowError occurs.
Except if it occurs in addKeyValue, then the exception is fatal:

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class Scratch {

    private static final Logger log = LoggerFactory.getLogger(Scratch.class);

    public static void main(String[] args) {
        log.atInfo().log("{}", new ToStringOverflow());
        System.out.println("slf4j could log");

        log.atInfo().setMessage("msg with key/value").addKeyValue("key", new ToStringOverflow()).log();
        System.out.println("slf4j could log with addKeyValue");
    }
}

class ToStringOverflow {

    @Override
    public String toString() {
        return super.toString() + this.toString(); // deliberately causes StackOverflowError
    }
}

14:28:10.399 [main] INFO pkg -- [FAILED toString()]
slf4j could log
Exception in thread "main" java.lang.StackOverflowError

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

No branches or pull requests

1 participant