Grails
  1. Grails
  2. GRAILS-8761

MetaClassRegistryCleaner? breaks XmlParser/Slurper

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0 final, 2.0.1
    • Fix Version/s: 2.0.1
    • Component/s: Testing
    • Labels:
    • Environment:
      Tested under Ubuntu 11.10 64-bit
    • Testcase included:
      yes

      Description

      The @ accessor for accessing attributes by name when parsing XML is broken between tests. An example is the easiest way of showing what I mean (have attached a project file too). I presume this is related to the MetaClassRegistryCleaner but haven't had a chance to look at the code yet.

      If either of the two tests below are run independently they work as you'd expect, but run both together and the second throws the error.

      HelloService.groovy
      class HelloService {
      	
      	def greet(message) {
      		def xml = "<greeting message='${message}'/>"
      
      		new XmlParser().parseText(xml).@message
      	}
      	
      }
      
      HelloServiceTests.groovy
      import org.junit.Test;
      import grails.test.mixin.*
      
      @TestFor(HelloService)
      class HelloServiceTests {
      	
      	@Test
      	void greetShouldReturnHello() {
      		assert service.greet('hello') == 'hello'
      	}
      	
      	@Test
      	void greetShouldReturnGoodBye() {
      		assert service.greet('goodbye') == 'goodbye'
      	}
      }
      
      groovy.lang.MissingFieldException: No such field: message for class: groovy.util.Node
      	at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:2490)
      	at groovy.lang.MetaClassImpl.getAttribute(MetaClassImpl.java:3316)
      	at org.codehaus.groovy.runtime.InvokerHelper.getAttribute(InvokerHelper.java:131)
      	at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.getField(ScriptBytecodeAdapter.java:302)
      	at HelloService.greet(HelloService.groovy:6)
      

      This was a complete pain to track down. It doesn't affect older style tests (unless there's a mixture of old and new)

      We spotted this JIRA (http://jira.grails.org/browse/GRAILS-8488) so tried this with the 2.0.1 snapshot and it fails there too.

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Graeme Rocher
            Reporter:
            James Frost
          • Votes:
            1 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:
              Last Reviewed:

              Development