Skip to content

StackOverflowError in addKeyValue is fatal #448

Description

@monnetchr

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions