Issue Details (XML | Word | Printable)

Key: JRUBY-65
Type: Bug Bug
Status: Closed Closed
Resolution: Fixed
Priority: Major Major
Assignee: Charles Oliver Nutter
Reporter: Tim Bray
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
JRuby

Text that comes out of Java APIs mixes poorly with text that doesn't

Created: 07/Aug/06 01:41 PM   Updated: 30/Apr/07 03:11 AM
Component/s: Java Integration
Affects Version/s: JRuby 0.9.0
Fix Version/s: JRuby 0.9.9

Time Tracking:
Not Specified

File Attachments: 1. File jrexml.rb (7 kB)
2. Text File jruby_seekable_io.patch (0.5 kB)
3. File t.rb (0.3 kB)

Environment: Latest Ubuntu, Java 1.5.0_06, latest JRuby


 Description  « Hide
If I build up a string in JRuby, some of which comes out of the Java libraries, there are anomalies. In the attached file I parse a chunk of XML then serialize it again out of the DOM. It contains some non-ASCII characters. If I puts it to STDOUT, it is converted to UTF-8. If I write it to a file, it is apparently broken.

 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order
Thomas E Enebo added a comment - 07/Aug/06 10:01 PM
This patch does fix your test case and also allows ant test to run. Unfortunately, it breaks rubygems.

Thomas E Enebo added a comment - 07/Aug/06 10:07 PM
I have a patch which fixes your problem attached. It also runs ant test fine. However, it dies in RubyGems and it is getting late for me; So I figured I may as well dump what I have right now.

Charles Oliver Nutter added a comment - 27/Sep/06 07:31 PM
Tom, you started a fix...got some time to wrap up the last minor issues?

Charles Oliver Nutter added a comment - 03/Apr/07 09:01 PM
This could actually be a larger issue now that we have a byte[]-based String impl. We need to address interop before 1.0, which means it should be in for 0.9.9.

Charles Oliver Nutter added a comment - 17/Apr/07 03:02 PM
If there was an encoding problem before, it doesn't seem to be present anymore. However it seems like this may now be an issue of when to flush a file. If I change the code in t.rb from this:

File.new("rd-bug", "w").write(e)

to this:

File.open("rd-bug", "w") {|f| f.write(e)}

The file contents match the stdout output. This tells me that a bare write on an open file, without an explicit close, does not get flushed to disk. Correct Ruby behavior appears to be that streams should close and flush on exit. I will file that as a separate bug.