levsha
levsha copied to clipboard
java.nio.BufferOverflowException from putToBuffer in StringHelper
This piece of code
def nodeFromHtml[T](html: String): LevshaNode[T] =
LevshaNode[T] { rc =>
val document: Elem = XML.loadString(html)
def aux(node: XmlNode): Unit =
node match {
case scala.xml.Text(text) =>
rc.addTextNode(text)
case _ =>
rc.openNode(XmlNs.html, node.label)
node.attributes.foreach { attr =>
rc.setAttr(XmlNs.html, attr.key, attr.value.head.text)
}
node.child.foreach { child =>
aux(child)
}
rc.closeNode(node.label)
}
aux(document.head)
}
can throw
[info] java.nio.BufferOverflowException: null
[info] at java.base/java.nio.Buffer.nextPutIndex(Buffer.java:730)
[info] at java.base/java.nio.HeapByteBuffer.putChar(HeapByteBuffer.java:342)
[info] at levsha.impl.internal.DefaultStringHelper.putToBuffer(StringHelper.scala:47)
[info] at levsha.impl.internal.DefaultStringHelper.putToBuffer$(StringHelper.scala:39)
[info] at levsha.impl.internal.StringHelper$.putToBuffer(StringHelper.scala:14)
[info] at levsha.impl.PortableRenderContext.addTextNode(PortableRenderContext.scala:139)
[info] at korolev.server.internal.services.PageService$RenderContextProxy.addTextNode(PageService.scala:66)
[info] at korolev.server.internal.services.PageService$RenderContextProxy.addTextNode$(PageService.scala:66)
[info] at korolev.server.internal.services.PageService$$anon$1.addTextNode(PageService.scala:39)
I tried to find the root cause hoping to fix it. But the usage of vars of type ByteBuffer makes it hard to trace what's going on. I think there is a leak somewhere.
I couldn't reproduce the issue with unit tests for the above function. It seems that the issue sometimes occurs when the function is used inside code blocks using Korolev DSL.
I can confirm that the issue occurs with Korolev 1.6.0-M2 and Levsha 1.4.0-M2. It is fine with Korolev 1.5.0 and Levsha 1.3.0.