[groovy-user] Passing '; ' as char to Java CSV parser throws 'no signature applicable' exception

117 views
Skip to first unread message

G...@gmx.net

unread,
Nov 16, 2012, 9:47:45 AM11/16/12
to us...@groovy.codehaus.org
Hello,

I want to parse a CSV file using the Apache commons CSV parser[1] but groovy throws an exception when passing the delimiter ';' as char, because groovy passes a java.lang.Character and the method expects a primitive char.

Given this small test case...

---
import org.apache.commons.csv.CSVFormat;
import org.apache.commons.csv.CSVParser;

def csv = """\
col1;col2
earth;10
mars;200
"""
def format = CSVFormat.DEFAULT.withDelimiter(';' as char)
.withQuoteChar(null)
.withSurroundingSpacesIgnored()
.withHeader()
def parser = new CSVParser(csv, format)
println(parser.getRecords())
---

...with the apache commons csv parser jar file[2] placed in $HOME/.groovy/lib, groovy will produce this error:

---
Caught: groovy.lang.MissingMethodException: No signature of method: org.apache.commons.csv.CSVFormat.withDelimiter() is applicable for argument types: (java.lang.Character) values: [;]
Possible solutions: getDelimiter()
groovy.lang.MissingMethodException: No signature of method: org.apache.commons.csv.CSVFormat.withDelimiter() is applicable for argument types: (java.lang.Character) values: [;]
Possible solutions: getDelimiter()
at test.run(test.groovy:9)
---

I have no idea why this is happening. The .withDelimiter() function exists[3] and takes a char. I went through heaps of information on Google and in the docs but I can't find a reason for why groovy wont pass a char. Afaik, groovy doesn't have a primitive char but supplying something "as char" to a java lib that expects a char should work, right? How else would I be able to use a java library method that expects a char?

Some more information:
* Groovy Version: 2.0.5 JVM: 1.6.0_24 Vendor: Sun Microsystems Inc. OS: Linux
* openjdk6 Version: 6.b24_1.11.5-1 (I also tried Oracle jdk 7.9 with the same outcome)
* Maybe this bug [4] plays a role?

Any help would be greatly appreciated. Thanks!

Regards,
Tim Berger


[1] http://commons.apache.org/csv/
[2] https://repository.apache.org/content/groups/snapshots/org/apache/commons/commons-csv/1.0-SNAPSHOT/commons-csv-1.0-20121115.232114-147.jar
[3] http://commons.apache.org/csv/apidocs/src-html/org/apache/commons/csv/CSVFormat.html#line.181
[4] http://jira.codehaus.org/browse/GROOVY-5189


---------------------------------------------------------------------
To unsubscribe from this list, please visit:

http://xircles.codehaus.org/manage_email


Hu, Yiguang

unread,
Nov 16, 2012, 9:50:40 AM11/16/12
to us...@groovy.codehaus.org
Why don't you just use String split?
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
Reply all
Reply to author
Forward
0 new messages