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

Wrapped Runnable and Callable should delegate toString() #1379

Open
shmosel opened this issue Sep 13, 2023 · 1 comment
Open

Wrapped Runnable and Callable should delegate toString() #1379

shmosel opened this issue Sep 13, 2023 · 1 comment

Comments

@shmosel
Copy link

shmosel commented Sep 13, 2023

When using CurrentTraceContext.wrap(), any custom toString() implementation from the underlying task is lost.

For example, say we have this class:

class Task implements Runnable {
    @Override
    public void run() {
        System.out.println("run");
    }

    @Override
    public String toString() {
        return "[Description]";
    }
}

And we pass an instance to a dead executor:

ExecutorService exec = Executors.newFixedThreadPool(1);
exec.shutdown();
exec.execute(new Task());

The output looks like this:

Exception in thread "main" java.util.concurrent.RejectedExecutionException: Task [Description] rejected from java.util.concurrent.ThreadPoolExecutor@26be92ad[Terminated, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]
	at java.util.concurrent.ThreadPoolExecutor$AbortPolicy.rejectedExecution(ThreadPoolExecutor.java:2063)
	at java.util.concurrent.ThreadPoolExecutor.reject(ThreadPoolExecutor.java:830)
	at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1379)
	...

But when it's passed through wrap(), we get the default brave.propagation.CurrentTraceContext$1CurrentTraceContextRunnable@224edc67 instead of [Description].

Shouldn't the wrapper delegate to the underlying toString() implementation?

@albertorugnone
Copy link

Yyhhmmilklkmmj~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants