groovy
  1. groovy
  2. GROOVY-3828

Groovy compiler chokes on MBCS in the script

    Details

    • Type: Bug Bug
    • Status: Closed Closed
    • Priority: Major Major
    • Resolution: Cannot Reproduce
    • Affects Version/s: 1.6.5
    • Fix Version/s: None
    • Component/s: parser
    • Labels:
      None
    • Environment:
      Linux Fedora(64 bit) with JDK 1.6.0_06
    • Testcase included:
      yes
    • Number of attachments :
      0

      Description

      If groovy script contains any multi byte char set groovy compiler fails and throws exception. How to make this program work?

      package project1;
      
      import groovy.lang.Binding;
      import groovy.lang.GroovyShell;
      
      import java.nio.ByteBuffer;
      import java.nio.CharBuffer;
      import java.nio.charset.Charset;
      
      import org.codehaus.groovy.control.CompilationUnit;
      import org.codehaus.groovy.control.CompilerConfiguration;
      import org.codehaus.groovy.control.ErrorCollector;
      import org.codehaus.groovy.control.MultipleCompilationErrorsException;
      import org.codehaus.groovy.control.SourceUnit;
      
      public class TestMBCSWithGroovy {
          public TestMBCSWithGroovy() {
              super();
          }
      
          public static void main(String[] args) {
              try {
                  byte[] b = { '' };
                  String encodingName = "UTF-8";
                  Charset cs = Charset.forName(encodingName);
                  ByteBuffer bb = ByteBuffer.wrap(b);
                  CharBuffer cb = cs.decode(bb);
                  String s = cb.toString();
                  //        s = new String(someBytes, encodingName);
                  //        s = "цец";
                  CompilerConfiguration debugConfiguration =
                      new CompilerConfiguration(CompilerConfiguration.DEFAULT);
                  debugConfiguration.setSourceEncoding(encodingName);
                  GroovyShell mGS =
                      new GroovyShell(Thread.currentThread().getContextClassLoader(),
                                      new Binding(), debugConfiguration);
                  CompilerConfiguration conf =
                      new CompilerConfiguration(CompilerConfiguration.DEFAULT);
                  ErrorCollector err = new ErrorCollector(conf);
                  SourceUnit src =
                      new SourceUnit("test", s, conf, mGS.getClassLoader(), err);
                  CompilationUnit compilationUnit = new CompilationUnit(conf);
                  compilationUnit.addSource(src);
                  compilationUnit.compile();
      
              } catch (MultipleCompilationErrorsException me) {
                  me.printStackTrace();
              }
      
          }
      }
      

      Exception:
      project1.TestMBCSWithGroovy
      org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, test: 1: unexpected char: 0x14 @ line 1, column 1.

      ^

      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:353)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.transformCSTIntoAST(AntlrParserPlugin.java:89)
      at org.codehaus.groovy.antlr.AntlrParserPlugin.parseCST(AntlrParserPlugin.java:61)
      at org.codehaus.groovy.control.SourceUnit.parse(SourceUnit.java:249)
      at org.codehaus.groovy.control.CompilationUnit$1.call(CompilationUnit.java:160)
      at org.codehaus.groovy.control.CompilationUnit.applyToSourceUnits(CompilationUnit.java:798)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:464)
      at org.codehaus.groovy.control.CompilationUnit.compile(CompilationUnit.java:443)
      at project1.TestMBCSWithGroovy.main(TestMBCSWithGroovy.java:44)
      Process exited with exit code 0.

        Activity

          People

          • Assignee:
            Guillaume Laforge
            Reporter:
            vijay redla
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: