HttpUrlConnection doOutput

when trying to use HttpUrlConnection (don’t ask why we’re not using Java 11, we’re just not.) and write to the output stream I get an error:

Exception in thread "main" cannot write to a URLConnection if doOutput=false - call setDoOutput(true)
at java.base/

yet in my code I have the following:
httpUrlConnection.doOutput = true

so something is wrong with the way Kotlin is accessing the setting. Had anyone else seen this?

Basic code:

val url = URL("")
httpConnection = url.openConnection() as HttpUrlConnection
httpConnection.doOutput = true
httpConnection.requestMethod = "POST"
bufferedWriter = BufferedWriter(OutputStreamWriter(httpConnection.outputStream))
bufferedWriter.write("some string")