You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by "John Wagenleitner (JIRA)" <ji...@apache.org> on 2016/04/27 02:06:12 UTC

[jira] [Commented] (GROOVY-7197) Strange behaviour during parent() method invocation on the non existent node (XmlSlurper).

    [ https://issues.apache.org/jira/browse/GROOVY-7197?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15259230#comment-15259230 ] 

John Wagenleitner commented on GROOVY-7197:
-------------------------------------------

This behavior does not seem to be caused just by a non-existent node, even asking for a parent of a parent of a existing node behaves the same:

{code}
def xml = '''
    <a>
      <b>
        <c/>
      </b>
    </a>
'''
def root = new XmlSlurper().parseText(xml)

def cNode = root.b.c

assert cNode.name() == 'c'

def cParent = cNode.parent()
assert cParent.name() == 'b'

def bParent = cParent.parent()
assert bParent.name() == 'a'
{code}

> Strange behaviour during parent() method invocation on the non existent node (XmlSlurper).
> ------------------------------------------------------------------------------------------
>
>                 Key: GROOVY-7197
>                 URL: https://issues.apache.org/jira/browse/GROOVY-7197
>             Project: Groovy
>          Issue Type: Bug
>          Components: XML Processing
>    Affects Versions: 2.3.7
>         Environment: Ubuntu 13.04, Groovy Console.
>            Reporter: Sergey Korsik
>
> I've migrated from Grails 2.2.5 (Groovy 2.0.8) to Grails 2.4.4 (Groovy 2.3.7) and some of my tests related to XmlSlurper start fail. 
> Maybe it's normal behavior for now, but doesn't look so. Here is an simple example which easily can be run in groovy console. 
> {code:java}
> def testedXml = '''
> <a>
>   <b>
>     <c>some cool text</c>
>   </b>
> </a>
> '''
> def root = new XmlSlurper().parseText(testedXml)
> def dNode = root.b.c.d
> //Use-case #1
> assert dNode.isEmpty()
> assert dNode.parent().name() == 'c'
> def cNode = dNode.parent()
> assert cNode.name() == 'c'
> // assume that node 'c' has node 'b' as parent
> assert cNode.parent().name() == 'b' // FAILED!
> //Use-case #2
> // Even if we try to convert from NodeParents to exect node.
> cNode = dNode.parent().getAt(0)
> assert cNode.name() == 'c'
> // assume that parent for node 'c' is 'b'
> assert cNode.parent().name() == 'b'// FAILED!
> {code}



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)