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" java.net.ProtocolException: cannot write to a URLConnection if doOutput=false - call setDoOutput(true)
at java.base/sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(HttpURLConnection.java:1349)

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("http://someurl.com")
httpConnection = url.openConnection() as HttpUrlConnection
httpConnection.doOutput = true
httpConnection.requestMethod = "POST"
bufferedWriter = BufferedWriter(OutputStreamWriter(httpConnection.outputStream))
bufferedWriter.write("some string")