Showing posts with label Groovy. Show all posts
Showing posts with label Groovy. Show all posts

Thursday, July 29, 2010

Grails LinkageError for SAXParseException

I ran "grails run-app" for the app that I've been working on and was greeted with the following :

java.lang.LinkageError: loader constraint violation: loader (instance of <bootlo
ader>) previously initiated loading for a different type with name "org/xml/sax/
SAXParseException"
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getDeclaredMethods(Class.java:1791)
at java.security.AccessController.doPrivileged(Native Method)
at org.codehaus.groovy.util.LazyReference.getLocked(LazyReference.java:4
6)
at org.codehaus.groovy.util.LazyReference.get(LazyReference.java:33)
at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.gr
oovy:127)
at grails.util.PluginBuildSettings.getPluginInfos(PluginBuildSettings.gr
oovy)
at grails.util.PluginBuildSettings$getPluginInfos.callCurrent(Unknown So
urce)
at grails.util.PluginBuildSettings.getPluginInfo(PluginBuildSettings.gro
ovy:164)
at grails.util.PluginBuildSettings$getPluginInfo.callCurrent(Unknown Sou
rce)
at grails.util.PluginBuildSettings.getPluginInfoForSource(PluginBuildSet
tings.groovy:202)
at org.codehaus.groovy.transform.ASTTransformationVisitor$3.call(ASTTran
sformationVisitor.java:303)
at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(Compil
ationUnit.java:832)
at org.codehaus.groovy.control.CompilationUnit.doPhaseOperation(Compilat
ionUnit.java:519)
at org.codehaus.groovy.control.CompilationUnit.processPhaseOperations(Co
mpilationUnit.java:495)
at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.j
ava:472)
at _GrailsEvents_groovy.run(_GrailsEvents_groovy:54)
at _GrailsEvents_groovy$run.call(Unknown Source)
at _GrailsClean_groovy$run.call(Unknown Source)
at _GrailsClean_groovy.run(_GrailsClean_groovy:29)
at _GrailsClean_groovy$run.call(Unknown Source)
$
at _GrailsPlugins_groovy.run(_GrailsPlugins_groovy:32)
at _GrailsPlugins_groovy$run.call(Unknown Source)
at _GrailsRun_groovy$run.call(Unknown Source)
at _GrailsRun_groovy.run(_GrailsRun_groovy:31)
at _GrailsRun_groovy$run.call(Unknown Source)
at RunApp.run(RunApp.groovy:25)
at RunApp$run.call(Unknown Source)
at gant.Gant.prepareTargets(Gant.groovy:606)
Error loading event script from file [PATH_TO_GRAILS\.grails
\1.3.1\projects\PROJECT_NAME\plugins\code-coverage-1.1.8\scripts\_Events.gr
oovy] loader constraint violation: loader (instance of <bootloader>) previously
initiated loading for a different type with name "org/xml/sax/SAXParseException"

Grails had done some sort of update that I didn't pay a lot of attention to. I wondered if this had something to do with the update and will have to find out what went on later.

I found an entry on the Grails Jira dealing with the problem of xerces and Java 6. The suggested solution was to remove xml-apis-1.0.2.b2.jar.

I ran :
find . -name "*xml*"
find . -name "*api*"
from my project directory, my .grails directory and my .ivy directory. I found xml-apis-1.3.04.jar in my .ivy directory.

I ran jarscan against my project directory, .grails directory and .ivy directory and found 0 hits for SAXParseException.

I added :

    inherits("global") {
excludes "xml-apis"
}

To my BuildConfig.groovy file just below dependencies. The app ran.

Friday, June 25, 2010

groovy.lang.MissingMethodException: No signature of method: static .list() is applicable for argument types:

I've started using Grails recently. Its really nice. Productive, easy to get up and running, etc.

My first stab at testing a Controller produced :
groovy.lang.MissingMethodException: No signature of method: static dbtestapp.Team.list() is applicable for argument types:
(org.codehaus.groovy.grails.web.taglib.GroovyPageAttributes) values: [[max:10]]
Possible solutions: is(java.lang.Object), wait(), wait(long), print(java.lang.Object), split(groovy.lang.Closure), use([Ljava.lang.Object;)
at dbtestapp.TeamController$_closure2.doCall
A little weird. list() is a dynamic method and should be on the object.

Its a known issue in the Grails Jira. The solution is to stick the test inside the "integration" package.

Monday, June 7, 2010

java.lang.ClassNotFoundException: org.codehaus.groovy.transform.powerassert.ValueRecorder

Running a GroovyTestCase in a new project I got the following :

java.lang.NoClassDefFoundError: org/codehaus/groovy/transform/powerassert/ValueRecorder
at [My Package Hierarchy].[My TestCase].[My Test Method]([My Test Case].groovy:29)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:168)
at junit.framework.TestCase.runBare(TestCase.java:134)
at junit.framework.TestResult$1.protect(TestResult.java:110)
at junit.framework.TestResult.runProtected(TestResult.java:128)
at junit.framework.TestResult.run(TestResult.java:113)
at junit.framework.TestCase.run(TestCase.java:124)
at junit.framework.TestSuite.runTest(TestSuite.java:232)
at junit.framework.TestSuite.run(TestSuite.java:227)
at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:79)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:46)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.ClassNotFoundException: org.codehaus.groovy.transform.powerassert.ValueRecorder
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
... 20 more
I found a bug that was closed because it couldn't be reproduced in the Groovy Eclipse JIRA.

I had run GroovyTestCases in other projects without this problem.

I right clicked the project and chose "Groovy -> Add Groovy libs to Classpath." That fixed it.

I had added my own Groovy library instead of the plugins. I often point Eclipse Libraries to the jar files in my .m2 directory. The "org.codehaus.groovy.transform.powerassert" package was not part of the Groovy distro. It is part of Groovy Eclipse plugin.

Tuesday, September 22, 2009

The excellent Mr. Haki blog

My morning routine has changed recently. I check out Mr. Haki, fire up the Groovy console and run the latest example.

I have been seriously impressed with the work Mr. Haki is doing.

Even if nobody reads this post, I want to at least help his search rankings!


Friday, September 11, 2009

"The processing instruction target matching "[xX][mM][lL]" is not allowed."

I often put the Xml I use for test cases inside of Groovy classes. This allows me to make use of multiline Strings.

String inputXml = '''
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<records>
<record>
<recordid>833432</recordid>
<name>Lorem ipsum dolor</name>
<parentid>0</parentid>
<link>http://consectetueradipiscingelit</link>
<date>9/10/2009</date>
<description>Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</description>
<category ID="48015"></category>
<category>In enim justo</category>
</record>
</records>
'''


I ran into this error today :

"The processing instruction target matching "[xX][mM][lL]" is not allowed."

I'm surprised I hadn't run into it before. The problem was that I had white space before the xml prolog.

There are two easy solutions :
  1. Remove the whitespace.
  2. Call "trim()" on the String.

Whitespace removed :
String inputXml = '''<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<records>
<record>
<recordid>833432</recordid>
<name>Lorem ipsum dolor</name>
<parentid>0</parentid>
<link>http://consectetueradipiscingelit</link>
<date>9/10/2009</date>
<description>Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</description>
<category ID="48015"></category>
<category>In enim justo</category>
</record>
</records>


trim() called :

String inputXml = '''
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<records>
<record>
<recordid>833432</recordid>
<name>Lorem ipsum dolor</name>
<parentid>0</parentid>
<link>http://consectetueradipiscingelit</link>
<date>9/10/2009</date>
<description>Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla consequat massa quis enim. Donec pede justo, fringilla vel, aliquet nec, vulputate eget, arcu.</description>
<category ID="48015"></category>
<category>In enim justo</category>
</record>
</records>
'''.trim()


Thursday, August 27, 2009

Unexpected Groovy return value

I like Groovy's multiline Strings. I use them all the time in my test cases. Usually I have a utility class that returns whatever content I need.

Yesterday I decided to do the whole test in Groovy. Inside my TestNG test case I had a method that returned some xml :

    String createInputFile(){
return
'''
<xml><one>Hello</one><two>World!</two></xml>
'''
}


The output was null. Kind of silly of me. Adding a semicolon after the String didn't produce an output. Putting the opening quote on the same line as the return statement did.

I still don't miss semicolons though.

Friday, April 25, 2008

Printing Arrays in Groovy

While working through the arrays page of the Getting Started Guide at the Groovy codehaus site, I stumbled upon some interesting behaviour. I was adding "print" statements to the following block of code :
assert a as List == ['a', 2, 'c', false] 
so that I ended up with :

print
"\na as List : " + a as List

The result wasn't what I expected :
["\n", "a", " ", "a", "s", " ", "L", "i", "s", "t", " ", ":", " ", "{", "\"", "a", "\"", ",", " ", "2", ",", " ", "\"", "f", "o", "o", "\"", ",", " ", "f", "a", "l", "s", "e", "}"] I added parentheses around the "a as List" and got what I expected : a as List : ["a", 2, "foo", false] Simple lesson : pay attention to precedence! That or drink coffee first thing in the morning.

Also, turning the whole string into a list that easily is cool.
Blogged with the Flock Browser