Groovy Duke
08/28/2023, 7:46 PMimport groovy.xml.StreamingMarkupBuilder
class TestMarkup{
private String toTF(value) {
return value ? "true" : "false"
}
Map status = [someBoolean: true]
def getBuilder(){
return new StreamingMarkupBuilder().bindNode {
Indicator(toTF(status?.someBoolean || status?.someBoolean))
}
}
}
new TestMarkup().getBuilder()
Any Ideas? I just got some steps to reproduce it so I'm going to try debugging it and see where that gets me.Groovy Duke
08/28/2023, 8:55 PMpaulk_asert
08/28/2023, 10:32 PMGroovy Duke
08/29/2023, 12:41 AMGroovy Duke
08/29/2023, 9:45 PMvirtualdogbert
08/30/2023, 10:35 AMbindNode
method of the StreamingMarkupBuilder
class, and that method/class should not be able to see private method. So it effectively calls owner.toIF( ... )
which you would expect to be an access violation.
You can actually evaluate the example you show there before calling the binder, and that value will be in the scope of the builder and so it should be able to see it. Although there may be instances elsewhere in your codebase that you can not do this, in which case the best option is to make the method public (as you have done) as it reflects the usage clearly.
Something like the following would work for the example...
class TestMarkup{
private String toTF(value) {
return value ? "true" : "false"
}
Map status = [someBoolean: true]
def getBuilder() {
// Executed in the scope of `TestMarkup` can see private scoped values.
final String indicatorVal = toTF(status?.someBoolean || status?.someBoolean)
return new StreamingMarkupBuilder().bindNode {
// Executed later by `StreamingMarkupBuilder` shouldn't be able to see values outside the scope of the `getBuilder` inner stanza
Indicator(indicatorVal)
}
}
}
new TestMarkup().getBuilder()
Groovy Duke [6:31 AM]
Interesting, this must have been a leak from Groovy 4 to 3 because in the Groovy 4 release notes:
We are currently attempting to improve how Groovy code accesses private fields in certain scenarios where such access is expected but problematic, e.g. within closure definitions where subclasses or inner classes are involved (GROOVY-5438). You may notice breakages in Groovy 4 code in such scenarios until this issue is progressed. As a workaround in the meantime, you may be able to use local variable outside a closure to reference the relevant fields and then reference those local variables in the closure.
However what is weird is in a fresh app the call to the private method will work, In a simple example like the one posted but in the app I'm working on the conditions are right for it to fail...
In any case thanks for the insight.blackdrag
08/30/2023, 12:25 PMblackdrag
08/30/2023, 2:16 PMclass Runner {
def run(cl) {
cl()
}
}
class A {
private foo() {1}
def bar() {
def runner = new Runner()
runner.run {->foo()}
}
}
class B extends A {}
def a = new A()
assert a.bar() == 1
def b = new B()
assert a.bar() == 1
This code works with 2.5.22, 3.0.18 and 4.0.13blackdrag
08/30/2023, 2:20 PMmatrei
08/30/2023, 2:20 PMassert b.bar() == 1
blackdrag
08/30/2023, 2:21 PMblackdrag
08/30/2023, 2:22 PMblackdrag
08/30/2023, 2:24 PMblackdrag
08/30/2023, 2:25 PMblackdrag
08/30/2023, 2:26 PMVampire
09/05/2023, 11:28 PMpublic <T> T Stub(Closure interactions)
in Java, that the type of the closure delegate is T
? ๐
Optimally, already with 2.5Vampire
09/08/2023, 10:44 PMrespondsTo
and hasProperty
variants or siblings that also consider category classes?blackdrag
09/09/2023, 6:48 AMbsdooby
09/11/2023, 3:29 PMblackdrag
09/11/2023, 3:45 PMbsdooby
09/11/2023, 4:01 PMbsdooby
09/11/2023, 4:01 PMblackdrag
09/11/2023, 4:13 PMblackdrag
09/11/2023, 4:15 PMbsdooby
09/11/2023, 4:23 PMbsdooby
09/11/2023, 4:23 PMblackdrag
09/11/2023, 4:36 PMsolvingj
09/16/2023, 5:23 PMBenjamin Marwell
09/25/2023, 1:52 PMjonnybot
09/26/2023, 3:17 PMGPathResult
back into a string using XmlUtil.serialize
, any emoji in the document are getting encoded as surrogate pairs, rather than the valid single character points. That leads to problems for me later when I try to parse the document using Jackson (see https://github.com/FasterXML/woodstox/issues/165 for an example of the error). It seems like I should be able to direct XmlUtil to serialize the unicode points into single entities (e.g. 🎅
instead of ��
). This is one of those things where I know I've dealt with it before and am just not coming up with the solution. Can anyone enlighten me / jog my memory?