Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,20 @@ class ProtoAuxiliarySpec extends AnyWordSpec, Matchers:
}
exception.getMessage should include("depth exceeded: 65")
}

"not preserve the cached size on clone()" in {
// .clone() should not preserve the cached size, as the cloned object will likely be modified
// right after cloning.
// Cloning while preserving the cached size leads to weird, hard-to-debug issues, for example:
// https://github.com/Jelly-RDF/cli/pull/126
val frame = RdfStreamFrame.newInstance()
.addRows(RdfStreamRow.newInstance().setTriple(RdfTriple.newInstance()))
val s = frame.getSerializedSize
s should be > 0
frame.getCachedSize should be (s)
val clonedFrame = frame.clone()
clonedFrame.getCachedSize should be(-1)
}
}

// Tests for the core-protos-google module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,11 @@ class MessageGenerator(val info: MessageInfo):
.addParameter(info.typeName, "other", Modifier.FINAL)
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
.returns(info.mutableTypeName)
copyFrom.addStatement("cachedSize = other.cachedSize")
// Reset cached size -- definitely do not copy it from the other message, because this object
// will likely be modified right after copying, leading to an incorrect cached size.
// Cloning while preserving the cached size leads to weird, hard-to-debug issues, for example:
// https://github.com/Jelly-RDF/cli/pull/126
copyFrom.addStatement("cachedSize = -1")
fields.foreach(_.generateCopyFromCode(copyFrom))
oneOfGenerators.foreach(_.generateCopyFromCode(copyFrom))
copyFrom.addStatement("return this")
Expand Down