Jump to content
  • Improve debugging of Groovy compile errors


    gcc
    Assigned User teodord
    CategoryBug report
    PriorityNormal
    ReproducibilityAlways
    ResolutionOpen
    SeverityMajor
    StatusNew

    I started getting this error in iReport:

     

    Compiling to file... /home/chris/workspace/rita/reports/org/wfp/rita/reports/dashboard.jasper

    Errors compiling /home/chris/workspace/rita/reports/org/wfp/rita/reports/dashboard.jasper!

    Compilation exceptions: com.jaspersoft.ireport.designer.compiler.ErrorsCollector@10abbd5d net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, calculator_Dashboard_1288084890631_785216: 201: unexpected token: this @ line 201, column 51. 1 error     at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:101)     at net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:188)     at net.sf.jasperreports.engine.JasperCompileManager.compileReport(JasperCompileManager.java:215)     at net.sf.jasperreports.engine.JasperCompileManager.compileReportToFile(JasperCompileManager.java:131)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:514)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:572)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:997) Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, calculator_Dashboard_1288084890631_785216: 201: unexpected token: this @ line 201, column 51. 1 error     at org.codehaus.groovy.control.ErrorCollector.failIfErrors(ErrorCollector.java:296)     at org.codehaus.groovy.control.ErrorCollector.addFatalError(ErrorCollector.java:143)     at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:113)     at org.codehaus.groovy.control.ErrorCollector.addError(ErrorCollector.java:125)     at org.codehaus.groovy.control.SourceUnit.addError(SourceUnit.java:348)     at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:85)     at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:244)     at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:143)     at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:772)     at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:438)     at net.sf.jasperreports.compilers.JRGroovyCompiler.compileUnits(JRGroovyCompiler.java:97)     ... 6 more

     

    This contains absolutely no useful information to debug the error.

     

    I ran the same report in my application under Eclipse, where I could put breakpoints on various methods in ErrorCollector where errors are added.

     

    I then discovered that the source code being compiled is obscured by being wrapped in a byte array, which makes it difficult to view in the Eclipse debugger. See JRGroovyCompiler.compileUnits():

     

    for (int i = 0; i < units.length; i++)

    {

    unit.addSource("calculator_" + units.getName(), new ByteArrayInputStream(units.getSourceCode().getBytes()));

    }

     

    This wrapping is unnecessary and inefficient, as there is an addSource() method that takes a String. There's no need to convert a string to a byte stream (including UTF-8 encoding) only to read it back again. And it obscures the source code that's being compiled in case of a compile error. It could be changed to:

     

    for (int i = 0; i < units.length; i++)

    {

    unit.addSource("calculator_" + units.getName(), units.getSourceCode());

    }

     

    Finally, together with config.setTolerance(0), this results in a useful error message from the Groovy compiler:

     

    Caused by: org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:

    calculator_Dashboard_1288088459888_30347: 199: unexpected token: this @ line 199, column 51.

    (java.lang.String)(Dispatches this month

    ^

    I haven't attached a patch, as this is a one-line change.



    User Feedback

    Recommended Comments

    There are no comments to display.


×
×
  • Create New...