4

I've been using Groovy for a few years, but not in the last few months, so this could just be a newbie question. I'm trying to parse a log file, but when I try to do this:

myFile.eachLine { line ->

        /* 2014 Jul 30 08:55:42:645 GMT -4 BW.TMSJobService-TMSJobService-1
         * User [BW-User] - Job-2584 [Process/Common/LogAuditInfo.process/WriteToLog]:   */
        /* 1234567890123456789012345678901 */
        /* 0        1         2         3  */

        LogItem logItem = new LogItem()
        // get the time stamp
        String timestamp = line.substring(0, 31)
        SimpleDateFormat sdf = new SimpleDateFormat('yyyy MMM dd HH:mm:ss:S')
        logItem.date = sdf.parse(timestamp)
    }

I get this exception:

Exception in thread "main" groovy.lang.MissingMethodException: No signature of method: java.text.SimpleDateFormat.parse() is applicable for argument types: (java.lang.String, ce.readscript.TmsLogReader$_read_closure1_closure3) values: [2014 Jul 30 08:34:47:079 GMT -4, ce.readscript.TmsLogReader$_read_closure1_closure3@14235ed5] Possible solutions: parse(java.lang.String), parse(java.lang.String, java.text.ParsePosition), parse(java.lang.String, java.text.ParsePosition), wait(), clone(), clone() at org.codehaus.groovy.runtime.ScriptBytecodeAdapter.unwrap(ScriptBytecodeAdapter.java:55) at org.codehaus.groovy.runtime.callsite.PojoMetaClassSite.call(PojoMetaClassSite.java:46) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:45)

It's always the last line in the closure. If I add code after the 'parse', then it bombs on this code. Even a "079".toLong() call gets a error.

I see some similar errors in stack overflow, but nothing that solves my problem.

2
  • Which groovy version? Commented Aug 5, 2014 at 13:32
  • The code you show there can't cause the exception shown. There must be some other factor that isn't represented in your code sample. Commented Aug 5, 2014 at 20:26

2 Answers 2

2

It is trying to invoke SimpleDateFormat::parse(String, Closure) which doesn't exist. There seems to be a typo somewhere. It is working fine under groovy 2.1.8 and 2.3.4. You can try to make it a bit more groovy, to check whether it has some typing error not in your example:

new File("log.log").eachLine { line ->
  def item = new LogItem()
  def timestamp = line[0..30]
  item.date = Date.parse('yyyy MMM dd HH:mm:ss:S', timestamp)
}
Sign up to request clarification or add additional context in comments.

Comments

1

I used the time honored technique of deleting the file and starting over. I haven't encountered the issue again.

1 Comment

Consider deleting the question. Is it useful to future visitors?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.