kotlin-compiler-server
kotlin-compiler-server copied to clipboard
Prevent stray output from reaching stdout
prevents prints that happen after (user's) main
return
s from polluting stdout.
Context: https://stackoverflow.com/questions/75714151/kotlin-coroutines-order-of-printing-logs/75760394#75760394
On second thought, not switching System.out back may cause stray prints become data races as the main thread reads from ByteArrayOutputStream
and the thread the prints writes to it.
But if that is the reason for calling setOut
, System.err
should also be switched back.
Or if the writes synchronize over the BAOS as I suggested in #619, the data race can be prevented by
synchronized(outputStream) {
outputObj.text = outputStream.toString()
.replace("</errStream><errStream>".toRegex(), "")
.replace("</outStream><outStream>".toRegex(), "")
}
Hi, is it possible to add a test (just a snippet to run)?
possible to add a test
Is the modified test sufficient? https://github.com/JetBrains/kotlin-compiler-server/pull/618#discussion_r1148465908
Following up on this.
I wasn't very clear in my previous comment. I have changed the test which now guards against the bug. I don't think a new additional test is needed.
The test that I modified, base coroutines test 7
used to only test for substring match.
Now it is testing for full equality.
This bug has confused another person.
https://stackoverflow.com/questions/77619172/why-does-the-kotlin-coroutine-output-a-b-even-with-a-delay
I found another SO question caused by this bug. Imagine how many people are confused by this but didn't ask a question.
https://stackoverflow.com/questions/71918773/why-does-coroutine-in-background-execute-before-the-main-thread-in-this-kotlin-c
@phiSgr, thank you for bringing this up! We are reviewing the PR, and I hope we can merge it this week.
No objections from my side. @phiSgr, thank you for the contribution!
@nikpachoo, thanks for merging this.
It seems to me that it's now deployed to https://play.kotlinlang.org only in version 2.0.0-RC2. Will it be back-ported to older versions as well?
@phiSgr, 1.9.24 version released today contains the fix ✅ There are no plans to back-port it to all the previous versions; their usage is relatively low. Thank you for your participation ❤️