Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows line endings confuse javac under linux #3714

Open
ruskotron opened this issue Mar 7, 2016 · 0 comments
Open

Windows line endings confuse javac under linux #3714

ruskotron opened this issue Mar 7, 2016 · 0 comments

Comments

@ruskotron
Copy link

FYI I have fixed this by simply changing the Windows line ending to Unix, but it is an interesting corner case I thought you should know about.

Basically I have a developer working in Windows environment who forgot to change her line endings to unix (as per our developer guidelines).

We perform our centralised build on a linux system and the jruby compile phase swallows the windows line endings and includes them in the string-literals used to represent the ruby in the generated java class.

Environment

Using jruby-complete-9.0.4.0.jar

Development using Windows 10

Build using CentOS Linux release 7.1.1503 3.10.0-229.20.1.el7.x86_64

java version "1.7.0_80"

Expected Behavior

I think that I would expect that DOS CRLF would be converted to newlines appropriate for java.

Actual Behavior

Javac stage of jruby compile complains about invalid characters.

My Ruby source (snippet):

require 'java'

require_relative 'LocalModule' if __FILE__ == $0

java_import 'some.package'

class MyRubyClass

etc etc

Compiled using java Ant task:

  <java jar="tools/jruby-complete-9.0.4.0.jar" fork="true" failonerror="true">
     <arg line="-S jrubyc --verbose --javac " />
     <arg prefix="-c" pathref="ruby.class.path" />
     <arg value="-t" />
     <arg file="test/classes" />
     <arg value="-d" />
     <arg file="test/ruby" />
     <arg line="test/ruby" />
  </java>

Produces this java source (vi output):

public class MyRubyClass extends RubyObject  {
    private static final Ruby __ruby__ = Ruby.getGlobalRuntime();
    private static final RubyClass __metaclass__;

    static {
        String source = new StringBuilder("require 'java'^M\n" +
            "^M\n" +

Notice ^M line-feed characters, which I believe are illegal in Java string literals.

Which results in the following output from my build-script:

ruby:
     [java] Compiling all in 'test/ruby'...
     [java] Generating Java class MyRubyClass to test/classes/MyRubyClass.java
     [java] javac  -d test/classes -cp /lib/:classes:test/classes/MyRubyClass.java 
     [java] test/classes/MyRubyClass.java:18: error: unclosed string literal
     [java]         String source = new StringBuilder("require 'java'
     [java]                                           ^
     [java] test/classes/MyRubyClass.java:19: error: illegal character: \92
     [java] \n" +
     [java] ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant